Android UI 的 Style 和 Theme

谷歌的文档很不错

Styles and Themes
Android Styles
Android Themes

摘录一些重点备忘

  • A style is a collection of properties that specify the look and format for a View or window.
  • To create a set of styles, save an XML file in the res/values/ directory of your project.
  • The parent attribute in the <style> element lets you specify a style from which your style should inherit properties.
  • If you want to inherit from styles that you've defined yourself, you do not have to use the parent attribute. Instead, just prefix the name of the style you want to inherit to the name of your new style, separated by a period.
  • To set a theme for all the activities of your application, open the AndroidManifest.xml file and edit the <application> tag to include the android:theme attribute with the style name.
  • If you want a theme applied to just one Activity in your application, then add the android:theme attribute to the <activity> tag instead.

最后还是上点代码

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="CodeFont" parent="@android:style/TextAppearance.Medium">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:textColor">#00FF00</item>
        <item name="android:typeface">monospace</item>
    </style>
    <style name="CodeFont.Red">
        <item name="android:textColor">#FF0000</item>
    </style>
    <style name="CodeFont.Red">
        <item name="android:textColor">#FF0000</item>
    </style>
</resources>
<application android:theme="@style/CustomTheme">
<activity android:theme="@android:style/Theme.Translucent">
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容