gpt4 book ai didi

java - 更改选定状态下的按钮形状?

转载 作者:行者123 更新时间:2023-12-01 22:06:48 25 4
gpt4 key购买 nike

我有一个 Android 按钮:

<Button
android:layout_width="wrap_content"
android:layout_height="44dp"
android:background="@drawable/action_button" />

action_button.xml 是:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<padding
android:left="25dp"
android:right="25dp"/>

<gradient
android:angle="0"
android:endColor="@color/whiteColor"
android:startColor="@color/whiteColor"/>

<corners android:radius="@dimen/borderRadius"/>

<stroke
android:width="2px"
android:color="@color/actionColor"/>
</shape>

按下按钮时如何更改形状?

最佳答案

您好,请使用下面的选择器并根据您的需要进行更改

选择器.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- <item android:state_enabled="false"
android:drawable="@drawable/cyan_strip" />
<item android:state_pressed="true"
android:drawable="@drawable/cyan_strip" />
<item android:state_pressed="false" android:state_focused="true"
android:drawable="@drawable/cyan_strip" />
<item android:drawable="@drawable/black_strip" /> -->

<item android:state_enabled="false">
<shape>
<solid
android:color="#4ec9d9" />
<stroke
android:width="1dp"
android:color="#FFFFFF" />
<padding
android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp" />
</shape>
</item>

<item android:state_pressed="true">
<shape>
<solid
android:color="#4ec9d9" />
<stroke
android:width="1dp"
android:color="#FFFFFF" />
<padding
android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp" />
</shape>
</item>

<item android:state_pressed="false" android:state_focused="true">
<shape>
<solid
android:color="#4ec9d9" />
<stroke
android:width="1dp"
android:color="#FFFFFF" />
<padding
android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp" />
</shape>
</item>

<item android:state_selected="true">
<shape>
<solid
android:color="#4ec9d9" />
<stroke
android:width="1dp"
android:color="#FFFFFF" />
<padding
android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp" />
</shape>
</item>

<item >
<shape>
<solid
android:color="#000000" />
<stroke
android:width="1dp"
android:color="#FFFFFF" />
<padding
android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp" />
</shape>
</item>

</selector>

关于java - 更改选定状态下的按钮形状?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32582514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com