我是全新的Android,我一直在尝试制作带有3个图像的图像按钮,默认情况下为焦点,按下按钮。 我试了很多我找到的例子,但我似乎无法让按钮响应焦点。图像按钮焦点不起作用
我在这个论坛上找到了下面的例子,它显示了按钮,并响应被按下,但它不会在焦点上改变。 谁能告诉我为什么?
我是全新的Android,我一直在尝试制作带有3个图像的图像按钮,默认情况下为焦点,按下按钮。 我试了很多我找到的例子,但我似乎无法让按钮响应焦点。图像按钮焦点不起作用
我在这个论坛上找到了下面的例子,它显示了按钮,并响应被按下,但它不会在焦点上改变。 谁能告诉我为什么?
您使用的选择,可以改变按钮后面的绘制?例如,您是否使用android:src="@drawable/selector1
。为您的按钮选择代码看起来应该(更多说明here):
<?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/but1_pressed" />
<item android:state_focused="true" android:drawable="@drawable/but1_focused" />
<item android:drawable="@drawable/but1_default" />
</selector>
我已经尝试过所有评论的版本,并且按钮出现,并且对点击作出响应 - 它在焦点上不会改变。有我缺少的设置吗?谢谢 – user987951
也许按钮不是可以调焦的?尝试添加到xml中的按钮布局:'android:focusable =“true”'和'android:focusableInTouchMode =“true”'。你也可以尝试从java代码中调用Button.requestFocus()来测试焦点函数。 – Kocus
创建一个新的文件夹的颜色命名的资源
2.一个了解创建.xml文件像按钮.XML所以它应该看起来像RES /颜色/ button.xml
3.在 .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_pressed"/> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/button_focused"/> <!-- focused -->
<item android:drawable="@drawable/button_default"/> <!-- default -->
</selector>
4.设置背景颜色@布局/button.xml
正是你想要西隧
? –
只是检查此:http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList –
看到这个:[Android Developer:StateListDrawable](http://developer.android.com/guide /topics/resources/drawable-resource.html#StateList)干杯! – COD3BOY