1.主题和样式的区别主要区别在
主题不能作用于单个View组建,主题应该对整个应用中的所有Activity起作用或者对指定的Activity起作用。
主题定义的格式应该是改变窗口的外观格式,例如窗口变体,窗口边框等。
2.自定义主题
在/res/values/my_style.xml文件增加一个主题,定义主题<style.../>片段如下:
<style name="CrazyTheme" parent="@android:style/Theme.Dialog"> <item name="android:windowNoTitle">true</item> <item name="android:windowFullScreen">true</item> <item name="android:windowFrame">@drawable/window_border</item> <item name="android:windowBackground>@drawable/star</item> </style>
可以通过parent属性,继承原有的主题。
在定义上面的主题后,接下来在Java代码中使用该主图:
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTheme(android.R.style.CrazyitTheme); setContentView(R.layout.linear_layout_3); }
还可以在AndroidManifest.xml中对指定应用、指定Activity应用主题,这样更简单:
<application android:theme="@style/CrazyitTheme"> ... ... </application>
<activity android:theme="@android:style/Theme.Dialog"> </activity>
3.Android系统包含了很多系统定义好的theme。总结如下: