27
2017
09

DialogActivity

1,在styles.xml中设置弹出式Activity的style样式

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

</resources>

2,设置Activity的Theme

<activity  android:name=".BluePairedActivity" android:theme="@style/DialogTransparent"></activity>

3,注意要设置成Dialog风格的Activity必须继承Activity而不能继承AppCompatActivity

public class BluePairedActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //窗口对齐屏幕宽度
        Window win = this.getWindow();
        win.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = win.getAttributes();
        lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.gravity = Gravity.CENTER;//设置对话框在屏幕中间显示
        win.setAttributes(lp);
        setFinishOnTouchOutside(false);//设置为true点击区域外消失
        setContentView(R.layout.activity_blue_paired);
    }
}

备注:如果定义成Dialog风格的Activity继承AppCompatActivity,会报错,详细信息请见

http://blog.csdn.net/zcn596785154/article/details/78098255

上一篇:Android MagicaSakura多主题框架 下一篇:Instruments 中 Leaks使用