0

Basically I change the background of 3 buttons on my main activity. Now, when I click the button it no longer highlights like it did before I changed the background. Somehow the background is causing this issue. No one else seem to be having quite the same issue. Am I doing something wrong?

NB: the button works fine, it's just the highlighting that doesn't.

My code for 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>

So after I changed the background of those buttons the highlight does not work. If you change it back to normal, then the highlight works fine.

Sled
  • 18,541
  • 27
  • 119
  • 168
x iHarpzZ
  • 151
  • 3
  • 16

1 Answers1

4

That's supposed to happen. You need to create a < selector > in your drawable folder and use it as the button's background, something like

<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>

where the drawables referred are images of just colors wrapped in a < drawable > element.

npace
  • 4,218
  • 1
  • 25
  • 35