如何改变颜色的按钮时,pressed在Android上的颜色? [英] How to change the color of the color button when pressed in Android?

查看:175
本文介绍了如何改变颜色的按钮时,pressed在Android上的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我单独设置它的背景色为红色,绿色和蓝色的一些按钮。当我preSS的按钮,点击时产生的事件,但在GUI中没有变化为知道该按钮在用户pssed $ P $。安卓按钮的默认背景灰色的颜色变为橙色,然后回来浅灰色释放pssed状态$ P $之后。如何在彩色按钮实现这一点?

I have some buttons which I set its background color as red, green and blue separately. When I press the button, click event is generated, but there is no change in gui for the user to know the button is pressed. Android button’s default background grayish color changes to orange and come back to grayish color after releasing the pressed state. How to implement this on colored button?

推荐答案

这是通过由 psented一个 StateListDrawable ,再$ P $实施选择中的 XML 的。参考:<一href="http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList">http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

That is implemented via a StateListDrawable, represented by selector in XML. Reference: http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

下面是一个例子的绘制的,这将是由白色的默认的,当黑色的 pressed 的:

Here is an example of a drawable that will be white by default, black when pressed:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
          android:drawable="@android:color/black" /> <!-- pressed -->
    <item android:drawable="@android:color/white" /> <!-- default -->
</selector>

这篇关于如何改变颜色的按钮时,pressed在Android上的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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