Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android borderless buttons

I hate to be the third person to ask this, but the previous two askings haven't seemed to answer it fully. The android design guidelines detail borderless buttons, but not how to make them. In one of the previous answers, there was a sugestion to use:

style="@android:style/Widget.Holo.Button.Borderless"

This works well for a Holo theme, but I use a lot of Holo.Light as well and

style="@android:style/Widget.Holo.Light.Button.Borderless"

Does not seem to exist. Is there a way to apply a style for such borderless buttons in Holo.Light, or better yet, simply apply a borderless tag without specifying which theme it belongs in, so the app can pick the proper style at runtime?

Holo.ButtonBar seems to fit the bill for what I am looking for, except it provides no user feedback that it's been pressed.

Also, is there a place in the documentation that lists such styles that can be applied and a description of them? No matter how much I google, and search through the docs, I can't find anything. There is just a non-descriptive list if I right click and edit style.

Any help would be appreciated.

Edit: Got a perfect answer from javram, and I wanted to add some XML for anyone interested in adding the partial borders google has adopted.

Fora horizontal divider, this works great

<View
    android:id="@+id/horizontal_divider_login"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:background="@color/holo_blue" />

and this for a vertical one:

<View
     android:id="@+id/vertical_divider"
     android:layout_width="1dip"
     android:layout_height="match_parent"
     android:layout_marginBottom="8dp"
     android:layout_marginTop="8dp"
     android:background="@color/holo_blue" />
like image 725
The Holo Dev Avatar asked Mar 14 '12 02:03

The Holo Dev


People also ask

How to change Button style android?

To change the default Button style of the application we can use the android:buttonStyle attribute in the AppTheme style inside the styles. xml.

How to use onClick method in android?

Onclick in XML layout When the user clicks a button, the Button object receives an on-click event. To make click event work add android:onClick attribute to the Button element in your XML layout. The value for this attribute must be the name of the method you want to call in response to a click event.


3 Answers

Simply add the following style attribute in your Button tag:

style="?android:attr/borderlessButtonStyle" 

source: http://developer.android.com/guide/topics/ui/controls/button.html#Borderless

like image 197
Diego V Avatar answered Sep 21 '22 01:09

Diego V


Check out my answer here. In a nutshell the correct solution is to use the following:

android:background="?android:attr/selectableItemBackground" 
like image 41
Paul Drummond Avatar answered Sep 23 '22 01:09

Paul Drummond


At the risk of beating a dead horse, here's another (possibly better) option. AppCompat v7 defines a borderless button style. If you're already making use of the AppCompat library, just go with that:

<Button android:text="@string/borderlessButtonText" style="@style/Widget.AppCompat.Button.Borderless" />

like image 22
wtracy Avatar answered Sep 20 '22 01:09

wtracy