gpt4 book ai didi

android xml选择器不起作用

转载 作者:行者123 更新时间:2023-11-29 15:04:41 25 4
gpt4 key购买 nike

我在 drawable 文件夹中创建了一个 xml 文件,用于在按下时更改按钮的颜色,使用这个

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

<!-- default -->
<item
android:state_pressed="false"
android:state_focused="false"
android:drawable="@drawable/purple"
/>

<!-- button focused -->
<item
android:state_pressed="false"
android:state_focused="true"
android:drawable="@drawable/darkpurple"
/>

<!-- button pressed -->
<item
android:state_pressed="true"
android:state_focused="false"
android:drawable="@drawable/lightpurple"
/>

这是我的按钮

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign In"
android:id="@+id/bt_login"
android:layout_gravity="top|left|bottom|right"
android:drawable="@drawable/button"
android:textColor="@android:color/white" />

我什至在 color.xml 中添加了颜色值

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="gray">#808080</color>
<color name="white">#ffffff</color>
<color name="background">#4F5680 </color>
<color name="purple">#04151f </color>
<color name="darkpurple">#0b3c59 </color>
<color name="lightpurple">#03141e </color>
<drawable name="purple">#04151f </drawable>
<drawable name="darkpurple">#0b3c59 </drawable>
<drawable name="lightpurple">#03141e </drawable>
</resources>

它只是不起作用,而不是像我预期的那样是紫色的

enter image description here ,

就是这样白

this

当我单击按钮时它会改变颜色,但会变成默认的灰色,这与我的预期不同。我的选择器有什么问题?

最佳答案

应该是

android:background="@drawable/button" 

代替这个

android:drawable="@drawable/button"

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

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