添加自定义颜色触摸Android的反馈 [英] Add custom color to touch feedback in android

查看:307
本文介绍了添加自定义颜色触摸Android的反馈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要为用户提供视觉反馈,当他们接触一个观点,我

To give users visual feedback when they touch a view, I do

<View
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="?attr/selectableItemBackground" />

?ATTR / selectableItemBackground 是一个灰色的颜色。我想用不同的颜色。要做到的的我

But ?attr/selectableItemBackground is a gray color. I want to use a different color. To do that I do

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="schemas.android.com/apk/res/android">;
    <item android:drawable="@color/mine" android:state_selected="true"></item>
    <item android:drawable="@color/mine" android:state_pressed="true"></item>
    <item android:drawable="@android:color/transparent"></item>
</selector>

但它不工作,即使我设置点击=真正的有问题的看法。

推荐答案

按照code

button_normal.xml

button_normal.xml

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

   <solid android:color="@color/button_light_green"/>
    <corners android:radius="5dp" />

</shape>

button_selected.xml

button_selected.xml

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

   <solid android:color="@color/button_light_green_selected"/>
    <corners android:radius="5dp" />

</shape>

button_background.xml

button_background.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@drawable/button_selected"/>
<item android:state_focused="true" android:drawable="@drawable/button_selected"/>
<item android:drawable="@drawable/button_normal"/> 
</selector>

通过改变其中U想要的颜色分配button_background.xml作为背景的​​按钮。希望工程!

assign button_background.xml as background for the button by changing the colors which u desire. Hope it works!!!

这篇关于添加自定义颜色触摸Android的反馈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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