Android支持自定义窗口的风格:
1)首先在资源里面建立style的value;
example:
1
2
3
| <style name="Theme.CustomDialog" parent="android:style/Theme.Dialog">
<item name="android:windowBackground">@drawable/filled_box</item>
</style> |
drawable/filled_box.xml:
1
2
3
4
5
6
7
| <shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#f0600000"/>
<stroke android:width="3dp" color="#ffff8080"/>
<corners android:radius="3dp" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
</shape> |
2)设置当前activity的属性,两种方式:
1.在manifest文件中给指定的activity增加属性
android:theme=”@android:style/Theme.CustomDialog”。
2.在程序中增加语句setTheme(R.style.Theme_CustomDialog);
注:如果只是将Acticity显示为默认的Dialog, 跳过1),只需要在manifest文中增加属性:android:theme=”@android:style/Theme.Dialog”或者在程序中增加setTheme(android.R.style.Theme_Dialog).
在测试中发现,在onCreate()事件中增加setTheme(),必须在setContentView()之前,否则指定的Style不能生效。
原文链接:http://stulog.com/?post=224