zoukankan      html  css  js  c++  java
  • android 按钮Button单击背景切换

    res/drawable/btn_selected.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
        <!-- 获得焦点但未按下时的背景图片 -->
        <item android:drawable="@drawable/ic_launcher" android:state_enabled="true" android:state_focused="true" android:state_pressed="false"/>
        <!-- 按下时的背景图片 -->
        <item android:drawable="@drawable/a" android:state_enabled="true" android:state_pressed="true"/>
        <!-- 按下时的背景图片 -->
        <item android:drawable="@drawable/a" android:state_checked="true" android:state_enabled="true"/>
        <!-- 默认时的背景图片 -->
        <item android:drawable="@drawable/ic_launcher"/>
    
    </selector>

    布局中设置按钮背景为btn_selected.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity" >
    
        <Button
            android:id="@+id/btn_user_selected"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_selected" >
        </Button>
    
    
    </RelativeLayout>
  • 相关阅读:
    牛人一个
    hdu 1106 排序
    中国历史上著名的年号
    十万个为什么 —— 名词解释(历史)
    十万个为什么 —— 名词解释(历史)
    数学可视化
    数学可视化
    高观点下的初等数学
    高观点下的初等数学
    同一性(identical)
  • 原文地址:https://www.cnblogs.com/androidsuperman/p/3473928.html
Copyright © 2011-2022 走看看