How to create borderless buttons in Android

Android design guides say using borderless buttons (see image below), but don't really explain how to do this. Someone asked the same question a few weeks ago here: How to create standard Borderless buttons (as in the mentioned design guide)? , and there was an answer designated as “answer, but I’m still lost and I don’t see a way to add comments to the question that was“ closed ”

Defendant said

"Look at the theme attributes buttonBarStyle , buttonBarButtonStyle and borderlessButtonStyle "

but I still can't figure out how to actually use these things. I ruined a little and could not find anything, so I decided that I would just ask this question again, and I hope someone can give a little more details about how this works.

enter image description here

+75
android layout button borderless
Feb 06 2018-12-12T00:
source share
8 answers

It seemed to me that I solved this when I looked here a few weeks ago and noticed the answer about using a transparent background, but it is not good enough because it prevents the button from being highlighted when pressed.

In addition, setting the style to Widget.Holo.Button.Borderless not suitable, since it makes the borders of the buttons large.

To understand this once and for all, I check the Android source code for the standard Calendar application and find that it uses the following:

 android:background="?android:attr/selectableItemBackground" 

Performing this method ensures that the button is borderless and the correct size.

+131
Mar 30 '12 at 23:00
source share

Take a look at this: http://developer.android.com/guide/topics/ui/controls/button.html#Borderless

Attribute of your Button or ImageButton :

  style="?android:attr/borderlessButtonStyle" 
+62
Jul 10 '12 at 17:08
source share

If you use ActionbarSherlock ...

 <Button android:id="@+id/my_button" style="@style/Widget.Sherlock.ActionButton" /> 
+24
Dec 07
source share

A few days ago I came across this again.

Here is my solution:

This is done in 2 steps: setting the background attribute of the android button : attr / selectableItemBackground creates a feedback button but does not have a background.

 android:background="?android:attr/selectableItemBackground" 

The line for dividing the borderless button on the rest of your layout is done using a view with android background : attr / dividerVertical

 android:background="?android:attr/dividerVertical" 

For a better understanding, here is the layout of the combination of OK / Cancel buttons without fields at the bottom of the screen (for example, in the right figure above).

 <RelativeLayout android:layout_width="match_parent" android:layout_height="48dp" android:layout_alignParentBottom="true"> <View android:layout_width="match_parent" android:layout_height="1dip" android:layout_marginLeft="4dip" android:layout_marginRight="4dip" android:background="?android:attr/dividerVertical" android:layout_alignParentTop="true"/> <View android:id="@+id/ViewColorPickerHelper" android:layout_width="1dip" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentBottom="true" android:layout_marginBottom="4dip" android:layout_marginTop="4dip" android:background="?android:attr/dividerVertical" android:layout_centerHorizontal="true"/> <Button android:id="@+id/BtnColorPickerCancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_toLeftOf="@id/ViewColorPickerHelper" android:background="?android:attr/selectableItemBackground" android:text="@android:string/cancel" android:layout_alignParentBottom="true"/> <Button android:id="@+id/BtnColorPickerOk" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:background="?android:attr/selectableItemBackground" android:text="@android:string/ok" android:layout_alignParentBottom="true" android:layout_toRightOf="@id/ViewColorPickerHelper"/> </RelativeLayout> 
+16
Jul 14 '12 at 5:27
source share

This code works for me:

 <View android:layout_width="match_parent" android:layout_height="1dip" android:background="?android:attr/dividerVertical" /> <LinearLayout style="?android:attr/buttonBarStyle" android:layout_width="match_parent" android:layout_height="wrap_content" android:measureWithLargestChild="true" android:orientation="horizontal" android:paddingLeft="2dip" android:paddingRight="2dip" android:paddingTop="0dip" > <Button android:id="@+id/cancel" style="?android:attr/buttonBarButtonStyle" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:onClick="onClickCancel" android:text="@string/cancel" /> <Button android:id="@+id/info" style="?android:attr/buttonBarButtonStyle" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:onClick="onClickInfo" android:visibility="gone" android:text="@string/info" /> <Button android:id="@+id/ok" style="?android:attr/buttonBarButtonStyle" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:onClick="onClickSave" android:text="@string/save" /> </LinearLayout> 

I will show 3 buttons below

+12
Apr 27 '13 at 18:04 on
source share
 android:background="@android:color/transparent" 
+7
Feb 06 2018-12-12T00:
source share
 <Button android:id="@+id/my_button" style="@android:style/Widget.Holo.Button.Borderless" /> 
+6
Feb 08 2018-12-12T00:
source share

You should also set the margins and padding the image to 0. Also look at the second, unchecked answer on How to create standard Borderless buttons (as in the mentioned design guide)?

0
Feb 06 '12 at 22:01
source share



All Articles