• 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>
  • 相关阅读:
    工业以太网的现状与发展
    软件开发的7大原则
    white-space
    vue使用better-scroll做轮播图(1.X版本 比较简单)
    windows 查看端口占用
    使用通知notication pendingIntent 传递参数
    fragment 创建optionsmenu
    android viewmodel 带参数
    LifecycleObserver 生命周期检测
    过河问题
  • 原文地址:https://www.cnblogs.com/androidsuperman/p/3473928.html
Copyright © 2020-2023  润新知