android开发关于CheckBox的深色模式和浅色模式下的适配

在values下的文件夹新建一个color.xml
在values-night下的文件夹新建一个color.xml
values下的文件夹里的:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="ir4s_radio_bg_u_dark">#1AFFFFFF</color>
    <color name="ir4s_radio_bg_u">#1A000000</color>
</resources>

values-night下的:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="ir4s_radio_bg_u">#1AFFFFFF</color>
</resources>

新建一个ir4s_radio_bg_s_light_2.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="#00D062" android:state_checked="true" android:state_enabled="true" />
    <item android:alpha="0.5" android:color="#00D062" android:state_checked="true" android:state_enabled="false" />
    <item android:color="@color/ir4s_radio_bg_u" android:state_checked="false" android:state_enabled="true" />
    <item android:alpha="0.5" android:color="#1A000000" android:state_checked="false" android:state_enabled="false" />
</selector>

在ir4s_checkbox_2.xml里引用

<?xml version="1.0" encoding="UTF-8"?>

<!-- Copyright (C) 2011 The Android Open Source ProjectLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License. -->

    <selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_checked="true" android:drawable="@drawable/ir4s_checkbox_checked"/>

    <item android:drawable="@drawable/ir4s_checkbox_unchecked_2"/>

</selector>

在style里引用ir4s_checkbox_2

  <style name="Ir4sItemViewSelectStyle" parent="@android:style/Widget.CompoundButton.CheckBox">
        <item name="android:button">@drawable/ir4s_checkbox_2</item>
    </style>

最后在页面的xml里的CheckBox里引用这个样式,示例:

       <CheckBox
            android:id="@+id/ck_child_checked"
            style="@style/Ir4sItemViewSelectStyle"
            android:layout_width="28dp"
            android:layout_height="28dp"
            android:layout_alignParentStart="true"
            android:layout_centerVertical="true" />
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值