如何使一个小闪光当按钮被窃听? [英] How To make a small flash when a button is tapped?

查看:192
本文介绍了如何使一个小闪光当按钮被窃听?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我做了有100多个按钮的Andr​​oid应用程序,但你知道,当你点击一个按钮,通常当你不改的背景或其他任何它闪烁橙色。但是,由于我添加了一个背景色为我的按钮时,他们拍了拍它只是转到下一屏幕,你不能告诉你已经挖掘一个按钮!

So I'm making an android app that has more than 100 buttons,but you know when you tap a button normally when you don't changed the background or anything it flashes orangish color. However since I've added a background color to my buttons when they're tapped it just goes to the next screen and you can't tell that you've tapped a Button!

有人能帮助我吗?
很抱歉,如果我不知道那些被称为:(

Could someone help me please? Sorry if I don't know what those are called:(

推荐答案

在可绘制声明这个选择并命名,例如:button.xml

Declare in drawables this selector and name it for example: button.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/btnPressed"/>
    <item  android:drawable="@drawable/btnNormal"></item>

</selector>

机器人:可绘制可颜色,图像,另一个绘制...
然后你可以声明按钮:

android:drawable can be color, image, another drawable... And then you can declare your button as:

<Button 
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:background="@drawable/button"
     />

如果您在创建$ C $您的按钮C​​,可调用的方法:setBackgroundResource(),并通过资源ID。
例如:

If you create your buttons in code you can call method: setBackgroundResource() and pass resource id. Example:

Button button = new Button(this);
button.setBackgroundResource(R.drawable.button);

http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

这篇关于如何使一个小闪光当按钮被窃听?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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