gpt4 book ai didi

android - 背景 xml 不工作

转载 作者:行者123 更新时间:2023-11-30 03:47:14 24 4
gpt4 key购买 nike

我有按钮,我想为它们设置背景 xml,当用户按下任何我想更改其背景的按钮时,我会这样工作

<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#FFFFFF"
android:gravity="center"
android:background="@drawable/button_selector"
android:text="@string/b_cancel" />

按钮选择器.xml

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

<item android:drawable="@drawable/button_bg" android:state_pressed="false" android:state_selected="false"/>
<item android:drawable="@drawable/button_bg_hover" android:state_pressed="true"/>
<item android:drawable="@drawable/button_bg_hover" android:state_pressed="false" android:state_selected="true"/>

</selector>

按钮_bg.xml

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

<padding android:top="10dip"
android:bottom="10dip"/>



<!-- Gradient Bg for listrow -->
<gradient
android:useLevel="false"
android:angle="270"
android:centerColor="#000000"
android:endColor="#FFFFFF"
android:startColor="#808080" />
</shape>

按钮_bg_hover.xml

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

<padding
android:bottom="10dip"
android:top="10dip" />

<!-- Gradient Bg for Button -->
<gradient
android:angle="270"
android:centerColor="#000000"
android:endColor="#FF0000"
android:startColor="#808080" />

</animation-list>

它作为背景效果很好,但当我按下按钮时,它变成了全白,启发了我的 button_bg_hover ,为什么要这样?什么是正确的?

最佳答案

可能是-tag放错了,换行

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
.....
</animation-list>

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

关于android - 背景 xml 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14788728/

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