android attr.xml my style

android attr.xml styles.xml

public RadioGroupEx(Context context, AttributeSet attrs) {
		super(context, attrs);
		TypedArray attributes = context.obtainStyledAttributes(attrs,
				R.styleable.RadioGroupEx, R.attr.RadioGroupExStyle,
				R.style.defRadioGroupExStyle);
               //defRadioGroupExStyle 是自定义默认的风格,RadioGroupEx 是默然读取的风格属性, 这是从属性读功能<xml>中使用,
              //RadioGroupExStyle 是我设定的风格属性读取点...这是在Style中的属性读取所以用attr.
                int n = attributes.getIndexCount();
		for (int i = 0; i < n; i++) {
			int attr = attributes.getIndex(i);
			switch (attr) {
			case R.styleable.RadioGroupEx_childPadding: //这里要用 styleable.属性组_组中属性.
				childPadding = (int) attributes.getDimension(
						R.styleable.RadioGroupEx_childPadding, 3);
				break;
			default:
				break;
			}
		}
		attributes.recycle();// 必须回收
		init();
	}
attr.xml

 <declare-styleable name="RadioGroupEx">
        <attr name="RadioGroupExStyle" format="reference" />
        <attr name="childPadding" format="dimension" />
    </declare-styleable>

styles.xml

  <style name="defRadioGroupExStyle"> //这个是上面代码设定的默认风格
        <item name="childPadding">12dp</item>
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <item name="RadioGroupExStyle">@style/defRadioGroupExStyle2</item> //因为属性中有RadioGroupExStyle是我设定的风格,可以在这设定自己的
    </style>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值