Android中样式styles和theme主题的使用方式

styles(样式)抽取出控件的共同的属性
    例如以下代码:
         <style name="my_text_style">
        <item name="android:textSize">20dip</item>
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:textColor">#ff0000</item>
            </style>
    如何继承style呢?
    第一种方式:
     <style name="my_text_style2" parent="@style/my_text_style">
        <item name="android:textColor">#0000ff</item>
        </style>
    第二种方式:
    <style name="my_text_style.my_text_style3">
        <item name="android:textColor">#00ff00</item>
        </style>
    第三种方式:

    在使用的时候,把想改变的属性给覆盖掉就行了。


theme的应用

1,创建主题
在styles xml文件中生成,其实theme是一个特殊的style
 <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
     
    </style>
    <style name="my_theme">
        <item name="android:background">#ff0000</item>
    </style>
2,主题的应用
在清单文件中的application中
<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/my_theme" >
根据自己写的样式中application中的theme选择
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值