Create background less button in android.
Making background less button is very easy developer can do this by simply adding android:background=”?android:attr/selectableItemBackground” tag in activity_main.xml file in android. So here is the complete step by step tutorial for Make Transparent button in android xml.
Make Transparent button in android xml.
Code for MainActivity.java file.
package com.android_examples.com.buttonwithoutbackground; import android.app.Activity; import android.os.Bundle; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }
Code for activity_main.xml layout file.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.android_examples.com.buttonwithoutbackground.MainActivity" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:background="?android:attr/selectableItemBackground" android:text="Button Without Background" /> </RelativeLayout>
Note: When you trying to add selectableItemBackground then it will show a error message ” ?android:attr/selectableItemBackground requires API level 11(current min is 8) ” so just change minimum api 8 to 11 in AndroidManifest.xml file. If you don’t know how to change api level then read my this post it will help you.
Screenshot: