android theme & style




  <!-- android:Theme.Light   @android:style/Theme.Light -->
这2种引用有何区别?
我的理解:
theme本身也是一种style,是针对的整个界面(Application or Activity)的效果,而style针对的是某一个控件(Button, TextView)的效果。
android:Theme.Light 的引用就当做是一种主题式的引用,而@android:style/Theme.Light 这样的引用就是当做style的引用。

 
<style name="BrowserThemeBase" parent="android:Theme.Light">
<item name="*android:windowTranslucentStatus">opaque</item>
</style>
 
<style name="BrowserThemeBase.BrowserTheme">
<!-- <item name="*android:windowTranslucentStatus">opaque</item>
*miui refer to a non-public attribute -->
<item name="*android:hidePopupArrow">true</item> 
<item name="android:actionBarStyle">@style/ActionBarNoTitle</item>
<item name="android:windowBackground">@color/white</item>
<item name="android:colorBackground">#FFFFFFFF</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>

  

注意下面的写法,经过测试发现,对于下面的写法:以BrowserThemeBase 已经有的属性为主,然后加上新的属性:
<style name="BrowserThemeBase.Fragment" >
     <item name="android:actionBarStyle">@null</item> 
</style>
 
下面的写法,以parent 继承的为主,会忽略掉 BrowserThemeBase 这个父的属性,就是说: BrowserThemeBase中定义的不会影响BrowserThemeBase.Fragment
<style name="BrowserThemeBase.Fragment" parent="miui:Theme.Light.ActionBar.NoTitle">
     <item name="android:actionBarStyle">@null</item>  
</style>


通过 点(.)来继承的这种方式 只适用与自定义的style继承。但是这句话似乎和我的测试结果有些出入,不管了,能用就行吧。然后在android官方文档找到了这个说明:

Note: This technique for inheritance by chaining together names only works for styles defined by your own resources. You can't inherit Android built-in styles this way. To reference a built-in style, such as TextAppearance, you must use the parent attribute.

对这句话:This technique for inheritance by chaining together names only works for styles defined by your own resources. 做一点解释:

比如:

  <style name="GreenText" parent="@android:style/TextAppearance">
        <item name="android:textColor">#00FF00</item>
  </style>
GreenText是我自己定义的,那么我后面就可以使用点继承这种方式了,如下:
  <style name="GreenText.Title">
        <item name="android:textSize">12sp</item>
  </style>
这样的话,我的 GreenText.Title 既包含了 GreenText 中定义的属性,也包含 GreenText.Title 中添加的属性。


对这句话 You can't inherit Android built-in styles this way. To reference a built-in style, such as TextAppearance, you must use the parent attribute. 做点解释:

比如系统中有个属性叫:@android:style/TextAppearance,你就不能这样用:

  <style name="@android:style/TextAppearance.Title">
        <item name="android:textSize">12sp</item>
  </style>

如果你想使用系统的属性,你就只能通过继承安卓系统中的属性,通过parent来实现了~


 




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值