按钮背景选择 [英] Button Background Selector

查看:120
本文介绍了按钮背景选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试试,如果他们是pressed切换按钮的背景。我建立一个像答案一个选择这里建议:<一href="http://stackoverflow.com/questions/1521640/standard-android-button-with-a-different-color">Standard Android的按键采用不同的颜色

I try to switch the background of Buttons if they are pressed. I build a Selector like the answer suggested here: Standard Android Button with a different color

最后我想提出GradientDrawables里面,但对于调试目的,我只是想设置一个颜色,看它是否工作。 这是我的选择。

finally I want to put GradientDrawables inside, but for debug purposes I only want to set a color, to see it is working. Here is my Selector

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

  <item android:drawable="@color/red"/>
  <item 
    android:state_focused="true"
    android:drawable="@color/white"/>
   <item 
    android:state_pressed="true"
    android:drawable="@color/white"/>
</selector>

不幸的是,这并不正常工作。我设置的选择从我的按钮背景,只看到他们在红色。我究竟做错了(构建目标2.1)

unfortunatly this doesn't work. I set the Selector as Background from my Button, and only see them in red color. What Am I doing wrong (Build Target 2.1)

推荐答案

把这个在最后

项机器人:可绘制=@色/红色

item android:drawable="@color/red"

我的意思是作为第三个选项,它会奏效。 安卓检查XML条件从一开始,第一个标签没有任何条件,所以它始终会选择红色,那么你已经把情况先升后默认的。

i mean as the third option, it will work. android checks the xml conditions from the start, the first tag doesn't have any condition, so it will always pick red, so you have put conditions first and then the default one.

这篇关于按钮背景选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆