2013-05-29 39 views
0

基本上我改變了我主要活動的3個按鈕的背景。現在,當我點擊按鈕時,它不再像我之前改變背景那樣突出顯示。不知何故背景導致了這個問題。沒有人看起來有相同的問題。難道我做錯了什麼?按鈕不會突出顯示點擊android

NB:該按鈕正常工作,它只是突出顯示沒有。

我對XML代碼:

<Button 
     android:id="@+id/Contact" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignRight="@+id/textView1" 
     android:layout_alignTop="@+id/linearLayout1" 
     android:layout_toRightOf="@+id/linearLayout1" 
     android:background="#f0e68c" //<<Here this background i changed 
     android:text="@string/Contact" /> 
<Button 
     android:id="@+id/Gallery" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="88dp" 
     android:layout_height="wrap_content" 
     android:background="#f0e68c" //<<Here this background i changed 
     android:text="@string/Gallery" /> 

</RelativeLayout> 

所以以後我改變了這些按鈕的亮點不工作的背景。如果您將其更改回正常,則突出顯示可正常工作。

+0

http://stackoverflow.com/questions/4131656/how-to-make-button-highlight – TronicZomB

+0

你需要使用stateListDrawable作爲背景。 http://developer.android.com/guide/topics/ui/controls/button.html#CustomBackground – Anirudh

回答

4

這應該發生。你需要在你的繪製文件夾一樣

<selector xmlns:android="http://schemas.android.com/apk/res/android" > 
<item 
    android:state_pressed="true" android:drawable="@drawable/btn_press"></item> 

<item 
    android:state_pressed="false" android:drawable="@drawable/btn_normal" ></item> 

這裏提到的可繪都的只是顏色包裹在一個<繪製>元素圖像創建<選擇>,並把它作爲按鈕的背景下,一些東西。

+0

這個代碼在哪裏去了。我怎樣才能得到可繪製的文件夾 –

+0

也是我有5. HDPI,MDPI,LDPI,XXDPI,XDPI –