所以我正在制作一个有超过 100 个按钮的 Android 应用程序,但是你知道当你正常点击一个按钮时,当你不改变背景或任何东西时,它会闪烁橙色。然而,由于我已经为按钮添加了背景颜色,当点击它们时,它只会进入下一个屏幕,并且您无法看出您已经点击了按钮!
有人可以帮我吗?
抱歉,如果我不知道这些叫什么:(
在drawables中声明这个选择器并将其命名为例如: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 可以是颜色、图像、另一个drawable...
然后你可以将你的按钮声明为:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button"
/>
如果您在代码中创建按钮,您可以调用方法:setBackgroundResource() 并传递资源 id。
例子:
Button button = new Button(this);
button.setBackgroundResource(R.drawable.button);
http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)