有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

如果单击按钮,java将显示活动图像

我想在单击按钮时显示活动图像。但是,如果我没有被点击,显示正常的图像样式。我该怎么做?请帮助我

图标\主页\配置。xml

    <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:安卓="http://schemas.安卓.com/apk/res/安卓">
    <item 安卓:state_pressed="true" 安卓:drawable="@drawable/home_button_hover" />
    <item 安卓:state_focused="true" 安卓:drawable="@drawable/home_button_hover" />
    <item 安卓:drawable="@drawable/home_button"/>
</selector>

共 (1) 个答案

  1. # 1 楼答案

    ImageView

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:src="@drawable/btn_background" />
    

    btn_背景。xml

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
    <item android:drawable="@drawable/btn_default_disabled_focused" android:state_focused="true" android:state_enabled="false"/>
    <item android:drawable="@drawable/btn_default_focused" android:state_focused="true" android:state_enabled="true"/>
    <item android:drawable="@drawable/btn_default_disabled" android:state_enabled="false"/>
    <item android:drawable="@drawable/btn_default_pressed" android:state_pressed="true"/>
    <item android:drawable="@drawable/btn_default_normal" />
    
    </selector>