style 引用时使用@还是?

本文详细解释了在Android开发中如何正确地使用@符号和问号?来引用资源,特别是style和Theme之间的区别。通过实例说明了这两种引用方式的不同之处。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转载地址:http://jiayanjujyj.iteye.com/blog/1392541

http://developer.android.com/guide/topics/resources/accessing-resources.html

http://hhliu-skills.blogspot.hk/2012/04/android-resource.html

http://blog.csdn.net/qinjuning/article/details/8829877

引用资源时使用@还是?的问题,我们在设置style的时候既可以使用@也可以使用?, 例如android:textAppearance="@andorid:style/TextAppearance.Medium", 

android:textAppearance="?android:attr/textAppearanceMedium"

使用@表示使用固定的style,而不会跟随Theme改变,这个style可以在style.xml中找到。

而?表示从Theme中查找引用的资源名,例如上面的textAppearanceMedium,查看themes.xml文件,可以看到在不同的theme中,textAppearanceMedium引用的style是不同的。如在Them.Holo中<item name="textAppearanceMedium">@android:style/TextAppearance.Holo.Medium</item>

,Theme.Holo.Light中为<item name="textAppearanceMedium">@android:style/TextAppearance.Holo.Light.Medium</item>


欢迎大家提出不同的意见。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值