android学习笔记1---用Activity来模拟、代替Dialog,使两者显示效果一致

首先定义好Activity,但是显示时,却不能像Dialog一样,周围透明,最后折腾一下,想到将Activity的theme设置为Dialog的就可以了。

style.xml中新定义一个新的style:

    <style name="sys_message_dialog" parent="@android:Theme.Dialog">
        <item name="android:windowFrame">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowBackground">@color/none</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:background">@null</item>            //因为我的activity中设置了带有4个圆角的背景图片,所以这个就要设置为@null,否则圆角体现不出来
    </style>

然后在AndroidManifest.xml中添加Activity。

        <activity
            android:name="com.lubian.car.view.SysMesgDialog"
            android:screenOrientation="landscape"
            android:theme="@style/sys_message_dialog"
         >

这样就搞定了!效果如图所示。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章