gpt4 book ai didi

android - 按钮选择器不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 10:26:05 24 4
gpt4 key购买 nike

我想在按钮不可点击时更改按钮的背景。我为此使用了选择器,但在按钮仍然不可点击的情况下它不起作用。

这是选择器文件:

<?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/button_lightgrey" />
<item android:state_pressed="true" android:state_enabled="true" android:drawable="@drawable/button_blue"/>
<item android:state_focused="true" android:drawable="@drawable/button_darkgreen" />
<item android:drawable="@drawable/button_lightgreen" />
</selector>

这是我在其中使用此选择器文件的按钮:

<Button
android:id="@+id/PrevButton"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:layout_marginLeft="5.0dip"
android:layout_weight="1.0"
android:background="@drawable/ibtn"
android:onClick="onPrevButtonClick"
android:text="Prev" />

请帮助我。所有其他功能都在选择器文件中工作,但只有不可点击按钮的情况不起作用。谢谢

最佳答案

代替 button.setClickable(false) 执行 button.setEnabled(false) 并使用相同的选择器 xml。

关于android - 按钮选择器不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12366256/

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