样式与主题1

Android可以这样定义样式:

res/values/styles.xml 文件中添加以下内容

<?xml version="1.0" encoding="utf-8"?>

  <resources>

    <style name = "itcast">

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

      <item name = "android:textColor"> #0000CC </item>

    </style>

    

    <!-- parent为继承上面的样式,也可以对继承的样式进行重载-->

    <style name = "sub" parent="@style/itcast">

      <item name = "android:textColor"> #00FFFF </item>

    </style>

  </resources>

 

layout文件中可以引用上面的android样式:

<?xml version="1.0" encoding="utf-8"?>

  <LinearLayout .....>

    <TextView style = "@style/itcast" />

  </LinearLayout>

 

 

================================================

 

Android主题的应用

res/values/styles.xml 文件中添加以下内容

<?xml version="1.0" encoding="utf-8"?>

  <resources>

    <style name = "itcastTheme">

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

    </style>

  </resources>

 

 

可以在AndroidManifest.xml中设置主题:

<application

        android:icon="@drawable/ic_launcher"

        android:label="@string/app_name" 

        android:theme = "@style/itcastTheme">

........

</application>

 

 

也可以在代码中设置主题:

setTheme(R.style.itcastTheme);

 

 

 

当主题中某个设置与控件样式中的设置冲突时,优先显示控件样式中的设置

 

来源: <http://blog.sina.com.cn/s/blog_a2614218010140mj.html>

 

Android系统的res: framework/base/core/res/res

 

style的引用方式

两种方式的区别:

第一种,存在则使用, 不存在则不用

第二种,直接使用, 不存在则空指针异常

 





posted @ 2016-10-01 11:52  杨伟乔  阅读(198)  评论(0编辑  收藏  举报