首页 > 代码库 > 给Activity设置Dialog属性,点击区域外消失;

给Activity设置Dialog属性,点击区域外消失;

1.在AndroidManifest.xml中给Activity设置样式;

<activity
            android:name=".MyActivity"
            android:theme="@style/MyDialog"
            android:label="@string/app_name" >

 

2.在res-value-style.xml中设置dialog样式;

<?xml version="1.0" encoding="utf-8"?>

<resources>
   
    <style name="MyDialog" parent="android:style/Theme.Dialog"> 
        <!-- 背景颜色及透明程度  -->
        <item name="android:windowBackground">@android:color/transparent</item> 
       <!--  是否有标题  -->
        <item name="android:windowNoTitle">true</item> 
       <!--  是否浮现在activity之上  -->
        <item name="android:windowIsFloating">true</item> 
        <!-- 是否模糊  -->
        <item name="android:backgroundDimEnabled">true</item> 
    </style>

</resources>

 

3. 在Activity中设置点击区域外消失属性;

 public  class MyActivity extends Activity {

@Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

    //////设置为true点击区域外消失
   setFinishOnTouchOutside(true);//   


  setContentView(R.layout.activity_layout);

  }

}

给Activity设置Dialog属性,点击区域外消失;