2014-09-11 62 views
0

我在屏幕上有一个图像按钮。如果我通过使用触摸屏单击按钮,图像焦点和按下所有按钮都可以正常工作。如果我用D'pad按钮处理同样的事情,会回到悬停状态,然后它移动到下一个屏幕,在我回到前一个屏幕后,它仍然保留悬停状态而不是默认状态。对于这种如何克服?图像按钮焦点问题

我的代码如下:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android" > 
     <item android:drawable="@drawable/cc_btn_vehicleinfo_pressed" 
      android:state_pressed="true" /> 
    <item android:drawable="@drawable/cc_btn_vehicleinfo_hover" 
      android:state_focused="true" 
      /> 
    <item android:drawable="@drawable/cc_btn_vehicleinfo_default"/> 
</selector> 
+0

@CommonsWare你能回顾THI我的问题 – Boopathi 2014-09-11 11:02:46

回答

0

看一看Styled Button它一定会帮助你的。有很多例子请在INTERNET上搜索。

如:风格

<style name="Widget.Button" parent="android:Widget"> 
    <item name="android:background">@drawable/red_dot</item> 
</style> 

您可以使用selector代替red_dot

您red_dot:

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="oval" > 

    <solid android:color="#f00"/> 
    <size android:width="55dip" 
     android:height="55dip"/> 
</shape> 

按钮:

<Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="49dp" 
     style="@style/Widget.Button" 
     android:text="Button" /> 
+0

选择器正常工作..请理解我的问题,我使用德垫时出现问题。 – Boopathi 2014-09-11 11:02:15