您好Stackoverflow的朋友。我在下面写了selector_button.xml
来点击我的按钮更漂亮。但它根本不会影响我的按钮。哪里错了?
这是selector_button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- When clicked -->
<item android:state_pressed="true"
android:state_selected="true" >
<shape >
<gradient
android:angle="90"
android:centerColor="@color/Lightgray"
android:endColor="@color/White"
android:startColor="@color/LightBlue"/>
<corners android:radius="12dip" />
<stroke
android:width="0dip"
android:color="@color/LightBlue" />
</shape>
</item>
<!-- When not clicked-->
<item >
<shape >
<gradient
android:angle="90"
android:centerColor="#ff008888"
android:endColor="@color/LightBlue"
android:startColor="@color/Lightgray"/>
<corners android:radius="12dip" />
<stroke
android:width="0dip"
android:color="@color/LightBlue" />
</shape>
</item>
</selector>
答案 0 :(得分:3)
<!-- When not clicked-->
<item android:state_pressed="false"> <!-- you need to define ur state to false-->
<shape >
<gradient
android:angle="90"
android:centerColor="#ff008888"
android:endColor="@color/LightBlue"
android:startColor="@color/Lightgray"/>
<corners android:radius="12dip" />
<stroke
android:width="0dip"
android:color="@color/LightBlue" />
</shape>
</item>
答案 1 :(得分:1)
更改为此(使用您的颜色)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When clicked -->
<item android:state_pressed="true"><shape>
<gradient android:angle="90"
android:centerColor="#999966"
android:endColor="@android:color/white"
android:startColor="#5E5EFF" />
<corners android:radius="12dip" />
<stroke android:width="0dip"
android:color="#5E5EFF" />
</shape></item>
<!-- When not clicked -->
<item android:state_selected="false"><shape>
<gradient android:angle="90"
android:centerColor="#ff008888"
android:endColor="#5E5EFF"
android:startColor="#999966" />
<corners android:radius="12dip" />
<stroke android:width="0dip"
android:color="#5E5EFF" />
</shape></item>
</selector>
答案 2 :(得分:0)
尝试这种方式兄弟:
<{1>}中的设置标签:
xml
<{1>}函数中的:
android:tag="0"
答案 3 :(得分:0)
将此属性添加到第二个商品标记中 ...
并确保将此按钮的背景设置为@ drawable / selector_button
答案 4 :(得分:0)
我终于解决了朋友指导的问题。我将代码更改为此并且工作正常。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- When clicked -->
<item android:state_pressed="true">
<shape >
<gradient
android:angle="90"
android:centerColor="@color/Lightgray"
android:endColor="@color/White"
android:startColor="@color/LightBlue"/>
<corners android:radius="12dip" />
<stroke
android:width="0dip"
android:color="@color/LightBlue" />
</shape>
</item>
<!-- When not clicked-->
<item android:state_pressed="false" >
<shape >
<gradient
android:angle="90"
android:centerColor="#ff008888"
android:endColor="@color/LightBlue"
android:startColor="@color/Lightgray"/>
<corners android:radius="12dip" />
<stroke
android:width="0dip"
android:color="@color/LightBlue" />
</shape>
</item>
</selector>