Android: Disable button's transparency

I'm making an app on Android and when I add a button with Eclipse's plugin the button is transparent.For example: http://kakko76.free.fr/buttontransparent.png But I don't want a transparent button! I tried with background attribute on button but I losed the other effect on click or others. How can I just disable button's transparency? Thanks.

Answers


By default the button shouldn't be transparent. However you could just create a Selector for your Button, so you can set it as its background but still have a click-effect whenever you click it.

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true" >
        <shape>
            <gradient
                android:startColor="insert color"
                android:endColor="insert color"
                />
            <stroke
                android:width="3dp"
                android:color="insert color" />
            <corners
                android:radius="3dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>



    <item android:state_pressed="false" >        
        <shape>
            <gradient
                android:endColor="insert color"
                android:startColor="insert color"
               />
            <stroke
                android:width="3dp"
                android:color="insert color" />
            <corners
                android:radius="3dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
</selector>

These are the default images for the Button in API Level <10 :

The selector:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/btn_erase_pressed" />
    <item android:state_focused="true" android:state_pressed="false"
        android:drawable="@drawable/btn_erase_selected" />
    <item android:drawable="@drawable/btn_erase_default" />
</selector>

And the images you'll find in your

\android-sdk\platforms\android-10\data\res\  folder

e.g:


Found the perfect and simplest solution:

Just set the background of your button to

android:background="@android:drawable/btn_default"

But make sure to do it directly in the XML, not in the "Graphic Layout" interface because it probably won't work

Hope it saves someone's day ;)


As i found the Ice-Cream resources, the button background image is transparent, so you need to change the background to your own image, using selectors.


Need Your Help

Security issues with opening a Socket with a url and port of an external machine to play streaming audio

java sockets security

Are there any security issues I should be aware of when opening a Socket connection with the url and port of a streaming radio station? I have written some code to do this, and I am beginning to w...

Reference ParseFiles stored in Parse via URL

image parse-platform pffile

I'm working on an iOS and Android that app sends an email that contains 2 images. It doesn't attach the images to the email, rather it links to them via URL using the src property of the img tag in...