zoukankan      html  css  js  c++  java
  • 一手遮天 Android

    项目地址 https://github.com/webabcd/AndroidDemo
    作者 webabcd

    一手遮天 Android - view(选择类): CheckBox 样式

    示例如下:

    /view/selection/CheckBoxDemo2.java

    /**
     * CheckBox - 复选框控件
     *     setButtonDrawable() - 设置复选框图片在各种状态下的样式
     *
     *
     * 本例主要介绍 CheckBox 的样式
     */
    
    package com.webabcd.androiddemo.view.selection;
    
    import androidx.appcompat.app.AppCompatActivity;
    import android.os.Bundle;
    import android.widget.CheckBox;
    
    import com.webabcd.androiddemo.R;
    
    public class CheckBoxDemo2 extends AppCompatActivity {
    
        private CheckBox _checkBox3;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_view_selection_checkboxdemo2);
    
            _checkBox3 = (CheckBox)findViewById(R.id.checkBox3);
            _checkBox3.setButtonDrawable(R.drawable.selector_checkbox_button);
        }
    }
    
    

    /layout/activity_view_selection_checkboxdemo2.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <!--
            CheckBox - 复选框控件
                button - 设置复选框图片在各种状态下的样式(参见 drawable/selector_checkbox_button.xml)
        -->
    
        <CheckBox
            android:id="@+id/checkBox1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:button="@drawable/selector_checkbox_button"
            android:text="checkBox1" />
    
        <CheckBox
            android:id="@+id/checkBox2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:button="@drawable/selector_checkbox_button"
            android:text="checkBox2" />
    
        <!--
            在 java 中设置 CheckBox 的 button
            调整复选框的图标与文字的间距可以通过 padding 来实现
        -->
        <CheckBox
            android:id="@+id/checkBox3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="10dp"
            android:paddingTop="10dp"
            android:text="checkBox2" />
    
    </LinearLayout>
    
    

    /drawable/selector_checkbox_button.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
        <!--
            state_enabled="true" - 可用
            state_enabled="false" - 不可用
            state_checked="true" - 选中
            state_checked="false" - 未选中
    
    
            注意:可以直接在 item 的 drawable 指定图片,但是这样只能按照原图的大小显示,如果需要指定图片的显示大小的话,则需要像本例这样使用 layer-list
        -->
    
        <item
            android:state_enabled="true"
            android:state_checked="true"
            android:drawable="@drawable/layerlist_checkbox_button_checked"/>
        <item
            android:state_enabled="true"
            android:state_checked="false"
            android:drawable="@drawable/layerlist_checkbox_button_unchecked" />
    </selector>
    

    项目地址 https://github.com/webabcd/AndroidDemo
    作者 webabcd

  • 相关阅读:
    leetcode------Sum Root to Leaf Numbers
    TesserOCR训练
    【转载】C#.Net 创建网页快捷方式
    错误:没有为扩展名“.html”注册的生成提供程序。
    【转载】错误 CS0016: 未能写入输出文件“c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files/.........dll”--“拒绝访问。 ”
    [转载]ASP.NET对路径"xxxxx"的访问被拒绝的解决方法小结
    [转载]ASP.NET对路径"xxxxx"的访问被拒绝的解决方法小结
    [转载]AFX_MANAGE_STATE关于资源切换
    OD鲜为人知的小技巧--搜索通配符(关键字)
    【转载】汇编跳转指令集
  • 原文地址:https://www.cnblogs.com/webabcd/p/android_view_selection_CheckBoxDemo2.html
Copyright © 2011-2022 走看看