2014-09-11 108 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