为资源Resource创建别名 引用style资源

Crete resources aliases

you can even use resources in XML to create aliases. For example, you can create adrawable resource that is an alias for another drawable resource:

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/other_drawable" />

This sounds redundant, but can be very useful when using alternative resource. Read more aboutCreating alias resources.


Referencing style attributes

A style attribute resource allows you to reference the valueof an attribute in the currently-applied theme. Referencing a style attribute allows you tocustomize the look of UI elements by styling them to match standard variations supplied by thecurrent theme, instead of supplying a hard-coded value. Referencing a style attributeessentially says, "use the style that is defined by this attribute, in the current theme."

To reference a style attribute, the name syntax is almost identical to the normal resourceformat, but instead of the at-symbol (@), use a question-mark (?), and theresource type portion is optional. For instance:

?[<package_name>:][<resource_type>/]<resource_name>

For example, here's how you can reference an attribute to set the text color to match the"primary" text color of the system theme:

<EditText id="text"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="?android:textColorSecondary"
    android:text="@string/hello_world" />

Here, the android:textColor attribute specifies the name of a style attributein the current theme. Android now uses the value applied to theandroid:textColorSecondarystyle attribute as the value for android:textColor in this widget. Because the systemresource tool knows that an attribute resource is expected in this context,you do not need to explicitly state the type (which would be?android:attr/textColorSecondary)—you can exclude theattr type.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值