问题有关更改按钮的颜色,当点击 [英] question about change the colours of a button when clicked

查看:205
本文介绍了问题有关更改按钮的颜色,当点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目的是改变一个按钮的颜色,当点击我的codeS是

My purpose is to change the color of a button when click and my codes are

<?xml version="1.0" encoding="utf-8"?>
selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- When selected, use grey -->
    <item android:drawable="@drawable/btn_askering_active" android:state_selected="true" />
    <!-- When not selected, use white-->
    item android:drawable="@drawable/btn_askering" />
</selector>

它的工作原理,但如果我做一个小的变化如下图所示:

It works but if i make a small change like below :

xmlns:android="http://schemas.android.com/apk/res/android">
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- When not selected, use white-->
    item android:drawable="@drawable/btn_askering" />
    <!-- When selected, use grey -->
    item android:drawable="@drawable/btn_askering_active" android:state_selected="true" />
</selector>

它不工作了....
我需要一些帮助...任何意见,欢迎here.Thanks

It does not work anymore.... I need some help...Any comments are welcomed here.Thanks

推荐答案

我认为你需要提及的统计中选择像$ P $据此pssed或突出重点,改变形象。
在这里,我附上样品选择的文件,看看,并相应地尝试。

I think you need to mention stats in selector like pressed or focused and change image accordingly. Here i have attached sample selector file,have a look and try accordingly.

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


    <item android:state_focused="true" android:state_pressed="false"
        android:drawable="@drawable/estimator_hover_new" />
    <item android:state_focused="true" android:state_pressed="true"
        android:drawable="@drawable/estimator_hover_new" />
    <item android:state_focused="false" android:state_pressed="true"
        android:drawable="@drawable/estimator_hover_new" />

    <item android:drawable="@drawable/estimator_new" />


</selector>

所有最好的....

All The Best....

这篇关于问题有关更改按钮的颜色,当点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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