zoukankan      html  css  js  c++  java
  • android中自定义checkbox的图片和大小

    其实很简单,分三步:

    1.在drawable中创建文件checkbox_selector.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    	<item android:state_checked="true" 
      		android:drawable="@drawable/checkbox_ok" /><!--设置选中图片-->
    	<item android:state_checked="false" 
     		android:drawable="@drawable/checkbox_empty" /><!--设置未选中图片-->
    </selector>


    2. 在values中创建styles.xml:

    <?xml version="1.0" encoding="utf-8"?>
    
    <resources>
    
      	<style name="MyCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox">
    
      	 <item name="android:button">@drawable/checkbox_selector</item>
    
      	 <item name="android:paddingLeft">25.0dip</item>
    
      	 <item name="android:maxHeight">10.0dip</item>
    
      	</style>
    
    </resources>


    3. 在你的CheckBox中添加属性:

    <CheckBox
            android:id="@+id/check"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_marginLeft="5dp"
            style="@style/MyCheckBox"  
            />


    搞定!这样就把你的checkbox换成你设置的那两张图片了

  • 相关阅读:
    log4j基本使用方法
    Spring MVC中页面向后台传值的几种方式
    JXL操作Excel
    模板
    url&视图
    Git for PyCharm
    ServletConfig和ServletContext
    Exception和IOException之间的使用区别
    java学习一目了然——异常必知
    java学习一目了然——IO
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3215112.html
Copyright © 2011-2022 走看看