zoukankan      html  css  js  c++  java
  • android:Style and Theme

    如果视图界面风格需要统一的规划,就需要使用android视图技术中的style。style的做法,是将这些style内容写到单独的xml文件中,放置在res/values/styles.xml中:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
       <style name="itemTitle">
               <item name="android:textSize">25sp</item>
               <item name="android:textStyle">bold</item>
       </style>
    </resources>

    使用:在布局文件中

    <TextView style="@style/itemTitle" ................/>

    R.java中有

    public static final class style {
    public static final int itemTitle=0x7f050000;
    }

     

     

    如果要针对整个Activity,对它的背景颜色和字体等做统一的样式约定,就需要使用另外一个技术,theme。

    首先,要编写theme文件,和style文件类似,是放在res/values目录下:(res/values/theme.xml)

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <color name="custom_background_color">#FFFFFFFF</color>
        <style name="RiverTheme" parent="android:Theme.Light">
            <item name="android:windowBackground">@color/custom_background_color</item>
        </style>
    </resources>
     

    这里继承了系统的theme.light,一般theme是继承的,这样可以对默认的风格不必重复定义。

    本例定义了一个背景色。这里背景色要单独声明,不能在item元素中直接写颜色值,会提示语法错误。

    引用该theme,在manifest文件中指定的Activity中:

    <activity .............
       android:theme="@style/RiverTheme"

    theme也可以在application中整体使用。。。

    参考:http://marshal.easymorse.com/archives/4111

  • 相关阅读:
    第三周作业
    第二周作业
    第一次作业(2)
    第一次作业
    百度翻译新API C#版在 winform,Asp.Net的小程序
    ajax 里的数据请求
    结合css与javascript来实现手机移动端的屏幕滑动效果
    js公农历互转(1900~2100年)
    webpack命令
    vscode快速输出console.log
  • 原文地址:https://www.cnblogs.com/mybkn/p/2491063.html
Copyright © 2011-2022 走看看