状态选择器

版权声明: https://blog.csdn.net/lyw_321/article/details/79798965



res-drawable-bg_login.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@android:color/holo_blue_light" android:state_pressed="false"/>

    <item android:state_pressed="true" android:drawable="@android:color/holo_red_light"/>

    
</selector>

res-layout-activity_main:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.lyw.selectedtest.MainActivity">

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/bg_login"
        android:text="登陆"
        />

</LinearLayout>

未点击按钮时:


点中按钮时:



猜你喜欢

转载自blog.csdn.net/lyw_321/article/details/79798965