Search code examples
androidbuttonalphaandroid-2.2-froyoandroid-2.3-gingerbread

Android Button Alpha looks weird on 2.2 and lower


Hello stackoverflowers!

This is my button:

<Button 
 android:layout_width="fill_parent"
 android:layout_height="0dp"
 android:layout_weight="0.30"
 android:text="@string/menu_button_newgame"
 android:id="@+id/button_newgame" 
/>

when I set it's alpha to 150 with

button_newgame.getBackground().setAlpha(150);

it starts looking weird on 2.2! On 2.3.3 the buttons look normally.

Android 2.3.3: (normal)

enter image description here

Android 2.2: (buggy)

enter image description here

What to do ?? :)


Solution

  • It seems to be a problem with the nine-patch.

    Try to use

    android:layout_height="wrap_content"
    

    All the buttons has the same content and they should keep the same height.

    Or try to create a custom nine-patch drawable to use as background.