zoukankan      html  css  js  c++  java
  • Activity使用Dialog样式导致点击空白处自动关闭的问题

    Activity使用Dialog样式导致点击空白处自动关闭的问题
    2013-06-09 10:02 8161人阅读 评论(5) 收藏 举报
    将Activity设置成窗口的样式实现Dialog或者Popupwindow效果在开发中是很常用的一种方式,在AndroidMenifest.xml中将需要设置的Activity增加android:theme="@android:style/Theme.Dialog"属性即可。但是窗口化的Activity有个问题就是:点击窗口空白处Activity会finish。如何避免这个问题呢,办法如下:
    一、如果API Level>=11有两种方式:
    1、
    resvaluesstyles.xml
    [html] view plaincopy
    <resources>  
        <style name="Theme.SoundRecorder" parent="@android:style/Theme.Holo.DialogWhenLarge">  
            <item name="android:windowCloseOnTouchOutside">false</item>  
        </style>  
    </resources>  (这种方法无效)


    2、
    [java] view plaincopy
    YourActivity.this.setFinishOnTouchOutside(false);  (这种方法有效)

    二、如果API Level<11
    [java] view plaincopy
    @Override  
        public boolean onTouchEvent(MotionEvent event) {  
            if (event.getAction() == MotionEvent.ACTION_DOWN && isOutOfBounds(this, event)) {  
                return true;  
            }  
            return super.onTouchEvent(event);  
        }  
      
        private boolean isOutOfBounds(Activity context, MotionEvent event) {  
            final int x = (int) event.getX();  
            final int y = (int) event.getY();  
            final int slop = ViewConfiguration.get(context).getScaledWindowTouchSlop();  
            final View decorView = context.getWindow().getDecorView();  
            return (x < -slop) || (y < -slop)|| (x > (decorView.getWidth() + slop))|| (y > (decorView.getHeight() + slop));  
        }  

  • 相关阅读:
    B
    Labyrinth 树的直径加DFS
    Speech to Text for iOS
    苹果开发者:Siri未开放API 有些让人失望
    ios6.0 siri语音识别
    Sample example for Speech to Text in iOS
    iOS升级经验分享
    苹果放宽了 iOS 5.0 对应用本地存储的限制
    iOS5可能会删除本地文件储存
    iOS 5 does not allow to store downloaded data in Documents directory? ios5.0及以后的版本对于下载的文件存储路径有了改变
  • 原文地址:https://www.cnblogs.com/zmc/p/4915540.html
Copyright © 2011-2022 走看看