zoukankan      html  css  js  c++  java
  • Styles and Themes

    A style is a collections of properties that specify the look and format of a view or window.

    They allow to separate the design from the content.

    Without Style XML, we can design it in the Layout XML:

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#00FF00"
        android:typeface="monospace"
        android:text="@string/hello" />

    With Style XML, we can turn it to:

    <TextView
        style="@style/CodeFont"
        android:text="@string/hello" />

    A theme is a style applied to an entire Activity of Application, rather than an individual view.

    When a style is applied as a theme, every View in the Activity or application will apply each style property that it supports.

    Then add an <item> element for each property of that style, with a name that declares the style property  and a value to go with it.

    Defining Styles

    The root node of the XML file must be <resources>.

    For each style you want to create, add a <style> element to the file with a name that uniquely identifies the style.

    Each child of the <resource> element  is converted into an application resource object at compile-time.

    Example:

    <?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>
    </resources>
     
    Inheritance
    The parent attribute in the <style> element lets you specify a style from which your style should inherit properties.
    Example
    <style name="GreenText" parent="@android:style/TextAppearance">
            <item name="android:textColor">#00FF00</item>
        </style>
     
    Style properties
    The best place to find properties that apply to a specific View is the corresponding class reference, which lists all of the supported attributes. 
    Example

    java.lang.Object

       ↳android.R.attr

    public static final int textColor

    Added in API level 1

    Color of text (usually same as colorForeground).

    May be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

    May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

    Constant Value: 16842904 (0x01010098)

  • 相关阅读:
    力扣238.除自身以外数组的乘积 & 剑指offer 51.构建乘积数组
    网易的Airtest
    ZOOKEEPER
    Apache和Nginx负载均衡集群及测试分析
    mysql——创建索引、修改索引、删除索引的命令语句
    sql-索引的作用
    ADB连接手机的两种方式(usb数据线连接和wifi连接)
    adb shell dumpsys 命令
    count(*) 和 count(1)和count(列名)区别
    博客园页面设置
  • 原文地址:https://www.cnblogs.com/johnpher/p/2909178.html
Copyright © 2011-2022 走看看