Theme(主题)

Theme简介

一个或者多个属性应用到整个屏幕;theme是作为一个属性被用到Manifest文件当中。

<activity

android:name="CustomTheme"

android:label="@string/app_name"

android:theme="@style/CustomTheme" >

</activity>

 

2)定义一个Style

<style name="myTheme">

<item name="android:windowNoTitle">true</item>

<item name="android:windowBackground">@drawable/init</item>

<item name="android:panelColorBackground">#33a</item>

<item name="android:panelColorForeground">#66a</item>

<item name="android:textSize">18sp</item>

<item name="android:textColor">?android:panelColorBackground</item>

<item name="android:textStyle">bold</item>

<item name="android:textColorLink">#fbb</item> 

</style>

/*  @:表示引用的资源已经在项目中或Framework 里定义了

*  ?:表示应用的资源在当前的Theme中

*/

 

3)使用自定义Theme

①、在AndroidManifest.xml文件中设置Theme应用于整个工程。

<application android:theme="@style/CustomTheme">

// Theme应用当前Activity

<activity android:theme="@android:style/Theme.Dialog" >

… …

②、代码中设置Theme          

protected void onCreate(Bundle savedInstanceState) { 

super.onCreate(savedInstanceState) ; 

setTheme(android.R.style.myTheme) ;

setContentView(R.layout.linear_layout_3) ;

}

posted @ 2016-06-14 11:09  权世爱  阅读(287)  评论(0)    收藏  举报