1

I am trying to use the Android Holo.Light theme and for some reason when I add a background image, it makes the buttons look very strange and see-through. Here is a screen shot:

enter image description here

Would anyone know why this happens? It looks very strange. Is it meant to be like that? Or am I doing something incorrectly?

When I had just Light as my theme, the same image was not see-through.

Thank you!

Genadinik
  • 18,153
  • 63
  • 185
  • 284
  • This is happening because the buttons by default in Holo.Light theme are a little transparent. You have to set your own nine patch drawable to remove this effect. – hardartcore Jun 03 '13 at 15:36

1 Answers1

2

The default for Holo buttons are slightly opaque. Just set a background drawable for them!

Here's an example of a gray button with a 1px outline. Includes the pressed state. You will set this on the button with "android:background="@drawable/gray_btn":

@drawable/gray_btn.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
    <shape>
        <solid
            android:color="#ffffff" 
            />
        <stroke
            android:width="1dp"
            android:color="#E3E3E3" />
        <corners
            android:radius="4dip" />

    </shape>
</item>
<item>
    <shape>
        <solid
            android:color="#edeff1" 
            />
        <stroke
            android:width="1dp"
            android:color="#E3E3E3" />
        <corners
            android:radius="4dip" />

    </shape>
</item>

Jameo
  • 4,507
  • 8
  • 40
  • 66
  • thank you - so is the setting that makes it not opaque the color? Or the solid setting? – Genadinik Jun 03 '13 at 15:35
  • Setting the background at all will do this. The theme automatically applies a drawable, but you will overrite this behavior. For example, if you set "android:background="#00000000", it would be completely transparent. Or "android:background="#ffffff", it would be completely white. And yes, solid is the main fill color. You can also do gradients – Jameo Jun 03 '13 at 15:44
  • To see how themes and styles work, you can check out this link http://developer.android.com/guide/topics/ui/themes.html. Also more on the shape drawable here http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape. FYI you can set any drawable to overrite this, including 9-patch – Jameo Jun 03 '13 at 15:46
  • sorry, I got confused :) What should I do to make the buttons not transparent? Does the background color need to be added to the buttons? If so, what would the snippet look like to just make them look solid? Thank you! – Genadinik Jun 03 '13 at 16:05
  • Did my code not work? Setting the "android:background" should do exactly that. Or, as I said, if you want a solid color, just set the hex color, as I said in my comments above. If for some reason that doesnt work, please copy and paste the XML from one of your buttons – Jameo Jun 03 '13 at 16:07
  • I am still trying to figure out where the xml with the button style should be placed. Does it go into the values directory? – Genadinik Jun 03 '13 at 16:15
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/31133/discussion-between-jameo-and-genadinik) – Jameo Jun 03 '13 at 17:08