-1

How do I add a button on a background image in Android?

I already added the background now I want to add a button and make it work within the background. I have tried to add multiple buttons but then they all don't work, I'm not sure if its the layout or something else.

This is what I have so far:

    <Button
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="back"
    android:id="@+id/button2"
    android:layout_alignTop="@+id/button"
    android:background="@drawable/scan1"
    android:layout_centerHorizontal="true"
    android:layout_alignParentStart="false"
    android:layout_alignParentLeft="false" />

i edited the code, so the "scan1" drawable is showing red.

Riley Java
  • 43
  • 9
  • 3
    please take a look at. http://stackoverflow.com/questions/4954102/button-background-as-transparent – humazed Aug 03 '16 at 10:47
  • you giving it a background image, how you expect it to be transparent ?!! – Muhammed Refaat Aug 03 '16 at 10:51
  • Muhammed, i got this image that has places where the buttons on the app should go, i made this my background image. now i want to put the buttons on those places then make them transparent so they blend with the background, i don't know if you understand me. – Riley Java Aug 03 '16 at 10:59

4 Answers4

0

Transparent button

 android:background="@null"

or

 android:background="@android:color/transparent"
Sanoop Surendran
  • 3,484
  • 4
  • 28
  • 49
Sohail Zahid
  • 8,099
  • 2
  • 25
  • 41
0

Use FancyButtons library to create buttons with transparent background. Set fb_defaultColor param as follows:

fancy:fb_defaultColor="@android:color/transparent"

Using this library, you won't lose ripple effects on button clicks.

Ugurcan Yildirim
  • 5,973
  • 3
  • 42
  • 73
0
 android:background="?android:attr/selectableItemBackground"

Add this to your button xml.. Hope it helps

Sanoop Surendran
  • 3,484
  • 4
  • 28
  • 49
0

You may also use: in your xml:

android:background="@null"

or in code:

button.setBackgroundColor(Color.TRANSPARENT);
balaji
  • 1,555
  • 5
  • 26
  • 49