• 定制知识积累


    若对系统自带的widget外观不满意,可以进行定制,原理是修改widget属性对应的drawable,操作步骤如下:

    1.在android系统的styles.xml/theme.xml中找到控件的属性所对应的drawable(图片或selector);

    2.在项目的styles.xml中自定义风格,继承系统风格,修改相应的drawable;

    3.在layout.xml中设置widget的style = "@style/自定义style";

    CheckBox定制

    1. 在sdk/platforms/android-**/data/res文件夹内搜索"styles.xml",并打开;
    2. 找到所需控件的style:
       <style name="Widget.CompoundButton.CheckBox">
           <item name="android:button">?android:attr/listChoiceIndicatorMultiple</item>
       </style>
      属性开头是"?",表明引用了系统的theme属性;
    3. 继续在当前目录内搜索"theme.xml",打开后找到"listChoiceIndicatorMultiple":
      <item name="listChoiceIndicatorMultiple">@android:drawable/btn_check</item>
    4. 再次搜索"btn_check",可以找到"btn_check.xml":
      <selector xmlns:android="http://schemas.android.com/apk/res/android">
      
          <!-- Enabled states -->
              
          <item android:state_checked="true" android:state_window_focused="false"
                android:state_enabled="true"
                android:drawable="@drawable/btn_check_on" />
          <item android:state_checked="false" android:state_window_focused="false"
                android:state_enabled="true"
                android:drawable="@drawable/btn_check_off" />
      
          <item android:state_checked="true" android:state_pressed="true"
                android:state_enabled="true"
                android:drawable="@drawable/btn_check_on_pressed" />
          <item android:state_checked="false" android:state_pressed="true"
                android:state_enabled="true"
                android:drawable="@drawable/btn_check_off_pressed" />
      
          <item android:state_checked="true" android:state_focused="true"
                android:state_enabled="true"
                android:drawable="@drawable/btn_check_on_selected" />
          <item android:state_checked="false" android:state_focused="true"
                android:state_enabled="true"
                android:drawable="@drawable/btn_check_off_selected" />
      
          <item android:state_checked="false"
                android:state_enabled="true"
                android:drawable="@drawable/btn_check_off" />
          <item android:state_checked="true"
                android:state_enabled="true"
                android:drawable="@drawable/btn_check_on" />
      
      
          <!-- Disabled states -->
      
          <item android:state_checked="true" android:state_window_focused="false"
                android:drawable="@drawable/btn_check_on_disable" />
          <item android:state_checked="false" android:state_window_focused="false"
                android:drawable="@drawable/btn_check_off_disable" />
      
          <item android:state_checked="true" android:state_focused="true"
                android:drawable="@drawable/btn_check_on_disable_focused" />
          <item android:state_checked="false" android:state_focused="true"
                android:drawable="@drawable/btn_check_off_disable_focused" />
      
          <item android:state_checked="false" android:drawable="@drawable/btn_check_off_disable" />
          <item android:state_checked="true" android:drawable="@drawable/btn_check_on_disable" />
      
      </selector>
      可知系统定义了该widget选中/未选中时的图片,因此定制时,通过创建style,继承系统的checkbox风格,引用自定义selector即可;
    5. 在项目drawable目录下创建"selector_my_checkbox.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/my_checkbox_selected" ></item>
          <item android:drawable="@drawable/my_checkbox_unselected"></item>
      </selector>
    6. 在项目values/styles.xml中自定义style:
       <style name="MyCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox">
           <item name="android:button">@drawable/selector_my_checkbox</item>
       </style>
    7. 设置CheckBox的属性即可:
       <CheckBox
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           style="@style/MyCheckBox"/>




  • 相关阅读:
    New Day
    apache mod_xsendfile 让php提供更快的文件下载
    XSS跨站测试代码大全
    HTML5 使用application cache 接口实现离线数据缓存
    HTTP 204 与 205 应用
    php HTTP请求类,支持GET,POST,Multipart/form-data
    php 过滤html标记属性类
    php 利用fsockopen GET/POST 提交表单及上传文件
    php 实现BigPipe分块输出
    同一域名对应不同IP,访问指定主机文件内容的方法
  • 原文地址:https://www.cnblogs.com/lynxz0620/p/4384928.html
Copyright © 2020-2023  润新知