如何更改按钮的颜色单击后? [英] How to change the color of button after click?
本文介绍了如何更改按钮的颜色单击后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建按钮的背景颜色,但是当我点击它,它不会显示任何东西。
我需要点击后显示不同颜色的按钮,因为用户需要知道的按钮
点击。照片
我不知道如何做到这一点?
给我的建议。
这里是我的按钮code。
<按钮机器人:TEXTSIZE =15px的
机器人:ID =@ + ID /按钮9
机器人:重力=中心|底
机器人:文字颜色=@色/ myWhiteColor
机器人:drawableTop =@可绘制/数学
机器人:文本=@字符串/ HomePage_Math
机器人:背景=@色/ myMaroonColor
机器人:layout_width =54dp
机器人:layout_height =WRAP_CONTENT>< /按钮>
保存在水库
解决方案
// XML文件/绘制/ button_bg.xml:
< XML版本=1.0编码=UTF-8&GT?;
<选择的xmlns:机器人=http://schemas.android.com/apk/res/android>
<项目的android:STATE_ pressed =真
机器人:颜色=#FFFF0000/> < - !pressed - >
<项目安卓state_focused =真
机器人:颜色=#FF0000FF/> <! - 集中 - >
<项目的android:颜色=#FF000000/> <! - 默认 - >
< /选择器>
//此布局XML将颜色列表应用到景观:
<按钮机器人:TEXTSIZE =15px的
机器人:ID =@ + ID /按钮9
机器人:重力=中心|底
机器人:文字颜色=@色/ myWhiteColor
机器人:drawableTop =@可绘制/数学
机器人:文本=@字符串/ HomePage_Math
机器人:背景=@可绘制/ button_bg
机器人:layout_width =54dp
机器人:layout_height =WRAP_CONTENT>< /按钮>
I create button with background color but when i click on it, it's not show anything.
I need to show different color on button after click because user need to know button is
Click.
I don't understand how to do this?
Give me suggestion.
here is my button code.
<Button android:textSize="15px"
android:id="@+id/button9"
android:gravity="center|bottom"
android:textColor="@color/myWhiteColor"
android:drawableTop="@drawable/math"
android:text="@string/HomePage_Math"
android:background="@color/myMaroonColor"
android:layout_width="54dp"
android:layout_height="wrap_content" ></Button>
解决方案
//XML file saved at res/drawable/button_bg.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:color="#ffff0000"/> <!-- pressed -->
<item android:state_focused="true"
android:color="#ff0000ff"/> <!-- focused -->
<item android:color="#ff000000"/> <!-- default -->
</selector>
//This layout XML will apply the color list to a View:
<Button android:textSize="15px"
android:id="@+id/button9"
android:gravity="center|bottom"
android:textColor="@color/myWhiteColor"
android:drawableTop="@drawable/math"
android:text="@string/HomePage_Math"
android:background="@drawable/button_bg"
android:layout_width="54dp"
android:layout_height="wrap_content" ></Button>
这篇关于如何更改按钮的颜色单击后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文