Reputation: 63
I'm trying to make an invisible button in android studio, but i have a problem. When i click on the button it turns orange as long as I hold it and I want to remove that so that the button is always invisible. I used this to make the button invisible: ?android:attr/borderlessButtonStyle. Please help, I looked everywhere but I couldn't find the solution. I'm a newbie at this so please make the explanation as simple as possible. Thanks!
Upvotes: 0
Views: 7974
Reputation: 370
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hapus"
android:background="#a41a1a"
android:id="@+id/btnhapus"
android:visibility="gone"/>
android:visibility="gone" for invisibility button, and android:visibility="visible" for visible button
Upvotes: 0
Reputation: 1344
android:visibility="gone" or android:visibility="invisible", this will remove your button from layout.
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="submit"
android:visibility="gone"
></Button>
Upvotes: 0
Reputation: 5451
You need to create selector under drawable folder and set color or image over there for different sates of the button.
I have created one sample application for you and am pasting code snippet:
Code for button_selector.xml that contains selector code for button which you will need to put under drawable folder:
<item android:drawable="@drawable/no_box_selector" android:state_pressed="true"></item>
<item android:drawable="@drawable/no_box"></item>
You will need to put no_box_selector and no_box pngs in drawable-hdpi or any drawable folders
Code for activity_main.xml that will be your main xml that contains only one button as of now:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relRingtone"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:orientation="vertical" >
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/button_selector"
android:padding="5dp"
android:text="Click Me"
android:textColor="#FFF"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
Try implementing these things and let me know if you need any further assisstance.....
All the best!!!
Reference : Disable pressed background color of button
Upvotes: 1