Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make button transparent in my app yet visible

I want my buttons to be transparent as I have an image on the activity as a background. If the buttons are not transparent, those buttons are covering the image and image background seems useless.

If I use android:background="@android:color/transparent", it is making my button completely invisible except the text on it. So, I need the button to be transparent provided it should be visible that there is a button. Code snippet would be appreciated.

<Button
android:id="@+id/new_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"  //this line makes the button completely invisible.
android:text="@string/label" />
like image 645
hrithik Avatar asked Oct 12 '12 10:10

hrithik


People also ask

How to create transparent background button in HTML?

The transparent button can be easily created by using HTML and CSS. In this article, we will use background-color: transparent; property to design the transparent background button. HTML Code: In this section, we will create a basic structure of button using the button Tag.

How to make apps transparent in iOS 14?

When stationary these icons will appear transparent. Here are the steps on how to make apps transparent in iOS 14: Now with the help of the search bar, choose the application whose icon you want to change In the menu, select choose photo or choose file according to where the user has saved the replacement image

How to add transparent background color in Android?

use #0000 (only four zeros otherwise it will be considered as black) this is the color code for transparent. You can use it directly but I recommend you to define a color in color.xml so you can enjoy re-usefullness of the code. Add this in your Xml - android:background="@android:color/transparent"

How do I change the transparency of a button color?

Go to Solution. 06-23-2021 05:56 AM The fillcolor properties of a Button use the RGBA () function to set the color. The fourth parameter of that function is the transparency from 0 fully transparent to 1 solid. Setting that value to a decimal or a percentage will adjust the transparency.


1 Answers

If you just want white borders, and the text/icons in the button, but the button background transparent create the following drawable (I named it button_border.xml):

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <stroke
                android:color="@android:color/white"
                android:width="1dp" />
            <solid android:color="@android:color/transparent" />
        </shape>
    </item>
</selector>

And use it as a background for the button:

<Button
    .
    .
    .
    android:background="@drawable/button_border"
    />

I'd guess there is a more elegant way to do it with themes, but I'm not that far yet. In the button_border drawable you can add rounded corners and whatnot...

like image 142
JNissi Avatar answered Oct 20 '22 08:10

JNissi