Android控件定制显示样式

1.CheckBox

<CheckBox
    android:id="@+id/chb_test"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:button="@drawable/check_bg"
    android:checked="true"
    android:text="喜欢"
    android:textColor="#dd0000"
    android:textSize="14dp" />
mChbTest = (CheckBox) findViewById(R.id.chb_test);
        mChbTest.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compondButton, boolean b) {
                if (b) {
                    toast("mChbTest选中");
                } else {
                    toast("mChbTest 没选中");
                }
            }
        });
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/ic_check_no" android:state_checked="false" />
    <item android:drawable="@drawable/ic_check_yes" android:state_checked="true" />
</selector>

2.RadioGroup

final RadioGroup mRgTest = (RadioGroup) findViewById(R.id.rg_test);
        mRgTest.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                RadioButton sb = (RadioButton) findViewById(mRgTest.getCheckedRadioButtonId());
                toast("选中:" + sb.getText());
            }
        });
<RadioGroup
                android:id="@+id/rg_test"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <RadioButton
                    android:id="@+id/radio_man"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="男" />

                <RadioButton
                    android:id="@+id/radio_women"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="女" />


            </RadioGroup>

3.RatingBar

<RatingBar
    android:id="@+id/rate_bar"
    style="@style/RateStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:isIndicator="false"//是否只是指示器
    android:numStars="5"
    android:rating="3"
    android:stepSize="1" />
<style name="RateStyle" parent="@android:style/Widget.RatingBar">
        <item name="android:progressDrawable">@drawable/start</item>
        <item name="android:minHeight">20dp</item>
        <item name="android:maxHeight">20dp</item>
    </style>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@android:id/background"
        android:drawable="@drawable/ic_start_off" />
    <item
        android:id="@android:id/secondaryProgress"
        android:drawable="@drawable/ic_start_on" />
    <item
        android:id="@android:id/progress"
        android:drawable="@drawable/ic_start_on" />


</layer-list>

4.ProgressBar

// 圆形进度条
<ProgressBar
    android:id="@+id/progress"
    style="?android:progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />
// 线形进度条
    <ProgressBar
        android:id="@+id/progress1"
        style="?android:progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="100"
        android:progress="50" />

自定义样式

针对线形进度条
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background">
        <shape android:shape="rectangle">
            <solid android:color="#dd0000" />
        </shape>
    </item>
    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape android:shape="rectangle">
                <solid android:color="#00dd00" />
            </shape>
        </clip>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape android:shape="rectangle">
                <solid android:color="#0000dd" />
            </shape>
        </clip>
    </item>


</layer-list>


<style name="lineProgressStyle" parent="@android:style/Widget.ProgressBar.Horizontal">
        <item name="android:progressDrawable">@drawable/progress_horizontal1</item>
    </style>
// 针对圆形
<style name="circleProgressStyle" parent="@android:style/Widget.ProgressBar.Large">
        <item name="android:indeterminateDrawable">@drawable/progress_red</item>
        <item name="android:minWidth">76dip</item>
        <item name="android:maxWidth">76dip</item>
        <item name="android:minHeight">76dip</item>
        <item name="android:maxHeight">76dip</item>
    </style>


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值