2013-02-27 45 views

回答

0

创建绘制选择的背景下,具有不同的状态不同的图像,

+0

我可以在我的java类上编码吗?像这样的东西。如果按钮被禁用,那么背景颜色=灰色 – Jerome 2013-02-27 11:34:23

+0

是的,你可以这样做也 – 2013-02-27 11:53:19

0

,你需要的是selector tags.You甚至不需要关心编程onFocus() etc.Its很容易和simple.You需要构建一个xml布局一次,它会完成剩下的工作。

加入您绘制按钮背景的绘制文件夹后,你需要添加一个 选择像这样的:

(RES /绘制/ new_button.xml)

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:drawable="@drawable/button_pressed_yellow" 
      android:state_pressed="true" /> 
    <item android:drawable="@drawable/button_focused_orange" 
      android:state_focused="true" /> 
    <item android:drawable="@drawable/button_normal_green" /> 
</selector> 

现在刚刚成立这个可拖动到你的按钮背景,如:

<Button 
     android:id="@+id/imageButtonSelector" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/new_button" /> 

你的作品已经完成。 Here是带有示例项目源代码的教程,供您参考。

+0

谢谢!这解决了我的问题 – Jerome 2013-02-27 12:35:32

+0

那么你应该把这个帖子标记为答案。这有助于其他用户在这里stackoverflow。 – Nezam 2013-02-27 12:53:26

相关问题