android 主题样式theme style区别

有时候这两个东西还真是会搞混了,记录一下:

1.主题应用于Activity或者整个Application,而style通常是应用于一个控件

2.主题和样式都是一堆属性的集合。区别在于,主题可以把一个控件的整个样式看成它的一个属性,如 ,只要包含在这个主题下的TextView,都会应用这个主题。而样式之针对具体的一个控件。因为主题和样式都可以定义在<style>中,所以很容易搞混了。

比如,定义了一个名为NumberPicker的控件,这个部分为属性定义

<resources>
<attr name="numberPickerStyle" format="reference" />

    <declare-styleable name="NumberPicker">
        <attr name="solidColor" format="color|reference" />
        <attr name="selectionDivider" format="reference" />
        <attr name="selectionDividerHeight" format="dimension" />
        <attr name="selectionDividersDistance" format="dimension" />
        <attr name="internalMinHeight" format="dimension" />
        <attr name="internalMaxHeight" format="dimension" />
        <attr name="internalMinWidth" format="dimension" />
        <attr name="internalMaxWidth" format="dimension" />
        <attr name="internalLayout" format="reference" />
        <attr name="virtualButtonPressedDrawable" format="reference"/>
        <attr name="enableSectionDivider" format="boolean"/>
		<attr name="rcNumberTextColor" format="color|reference"/>
		<attr name="selectedNumberTextColor" format="color|reference"/>
        <attr name="indicatorLayout" format="reference"/>
    </declare-styleable>
</resources>

如果要定义这个控件的属性不用多说,下面主要看怎么控制整个Activity或者属性的:

style的定义:

<style name="Theme.hehe" parent="@style/Theme.heihei">
        <item name="numberPickerStyle">@style/theNumberPickerStyle</item>
    </style>


Manifest中:

<activity
            android:name="com.xxx"
            android:screenOrientation="portrait"
            android:theme="@style/Theme.hehe" />

这样,只要在com.xxx Activity中的numberPicker,就会应用上面theNumberPickerStyle的属性~

不明白就留言吧,我偷懒了。。。


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值