您的位置:首页 > 其它

Style Resource

2016-04-05 12:44 375 查看
A style resource defines the format and look for a UI. A style can be applied to an individual 
View
 (from
within a layout file) or to an entire 
Activity
 or application (from within the manifest
file).

For more information about creating and applying styles, please readStyles and Themes.

Note: A style is a simple resource that is referenced using the value provided in the 
name
 attribute (not the name of the XML file). As such, you can combine style resources with other simple resources in the one XML file,
under one 
<resources>
 element.
FILE LOCATION:
res/values/filename.xml


The filename is arbitrary. The element's 
name
 will be used as the resource ID.RESOURCE REFERENCE:In XML: 
@[package:]style/style_name
SYNTAX:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style
        name="style_name"
        parent="@[package:]style/style_to_inherit">
        <item
            name="[package:]style_property_name"
            >style_value</item>
    </style>
</resources>

ELEMENTS:

<resources>
Required. This must be the root node.
No attributes.
<style>
Defines a single style. Contains 
<item>
 elements.
attributes:
name
String. Required. A name for the style, which is used as the resource ID to apply the style to a View, Activity, or application.
parent
Style resource. Reference to a style from which this style should inherit style properties.
<item>
Defines a single property for the style. Must be a child of a 
<style>
 element.

attributes:
name
Attribute resource. Required. The name of the style property to be defined, with a package prefix if necessary (for example 
android:textColor
).EXAMPLE:
XML file for the style (saved in 
res/values/
):
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="CustomText" parent="@style/Text">
        <item name="android:textSize">20sp</item>
        <item name="android:textColor">#008</item>
    </style>
</resources>

XML file that applies the style to a 
TextView
 (saved
in 
res/layout/
):
<?xml version="1.0" encoding="utf-8"?>
<EditText
    style="@style/CustomText"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Hello, World!" />

样式资源定义的格式,并寻找一个UI。样式可以应用于单个
视图
(从布局文件内)或整个
活动
(从清单文件内)或应用程序。

有关创建和应用样式的更多信息,请阅读 样式和主题

注意:样式是使用在所提供的值引用的一个简单的资源
名称
属性(未XML文件的名称)。因此,你可以风格的资源与其他资源的简单一个XML文件中结合起来,在一个
<资源>
元素。
文件位置:
RES /价值/ 文件名 ​​的.xml


的文件名 ​​是任意的。元素的
名字
将被用作资源ID。资源引用:在XML:
@ [包:]风格/ STYLE_NAME
句法:
<?xml的version = "1.0" encoding = "utf-8" ?>
< resources >
    < style
         name = " style_name "
        parent = "@[package:]style/ style_to_inherit " >
        < item
            name = " [package:]style_property_name "
            > style_value </ item >
    </style>
</resources>

内容:

<资源>
必选项。这必须是根节点。
无属性。
<STYLE>
定义一个样式。包含
的<item>
元素。
属性:
名称
字符串,必需。一种用于样式,其被用作资源ID的样式应用于一个视图,活动,或应用程序的名称。
样式资源。参考从中这种风格要继承样式属性的样式。
<项目>
定义样式的一个属性。必须是一个孩子 
的<style>
元素。

属性:
名称
属性资源。必需。要定义的样式属性的名称,以包前缀,如果有必要(例如
机器人:文字颜色
)。例:
对于风格的XML文件(保存在
RES /价值/
):
<?XML版本= “1.0” 编码= “UTF-8” ?>
<资源>
    <样式 名称= “CustomText”  父= “@风格/文本” >
        < 项目名称= “机器人:TEXTSIZE” > 20SP </ 项>
        < 项目名称= “机器人:文字颜色” >#008 </ 项目>
    </作风>
</资源>

该样式应用到一个XML文件中
的TextView
 (保存在
RES /布局/
):
<?xml的

   
   
   
    世界!“  />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息