26

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" />
Community
  • 1
  • 1
The Holo Dev
  • 1,016
  • 3
  • 12
  • 22

5 Answers5

47

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

Ziem
  • 6,579
  • 8
  • 53
  • 86
Diego V
  • 6,189
  • 7
  • 40
  • 45
30

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

android:background="?android:attr/selectableItemBackground"
Community
  • 1
  • 1
Paul Drummond
  • 6,043
  • 6
  • 30
  • 38
12

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" />

wtracy
  • 133
  • 1
  • 5
8

This code will remove all background for a button:

android:background="@android:color/transparent"
javram
  • 2,635
  • 1
  • 13
  • 18
  • That seems like an answer that is much to simple to take 3 questions to answer, but it does the trick exactly. Also, for anyone seeing this later and wondering, to get the semi-borders google has adopted, I added some code that worked for me in the first post, since posting code in sub-responses is hard to read. – The Holo Dev Mar 14 '12 at 04:58
  • I remember thinking the same thing when I was trying to figure this one out. I am using it as a hyperlink, which should have been a relatively simple task, or so I thought... – javram Mar 14 '12 at 05:00
  • I don't get user feedback, when pressing the borderless button. No highlight or anything. Did I miss something? – Konsumierer Feb 02 '13 at 15:13
  • @dead I do not get the API 11 requirement. My min is set to 10. – bradj Mar 21 '13 at 18:50
1

Just incase anybody is looking for light-weight solution to get the borderless button for the API's that do not support the Holo theme (like I did for a long time), Im posting my solution below:

<View 
    android:layout_height="1dp"
    android:layout_width="match_parent"
    android:background="#505154"
    android:layout_marginLeft="10dp" android:layout_marginRight="10dp"/>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <Button
        android:id="@+id/btn_Reply"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:background="@android:color/transparent"
        android:paddingBottom="15dp" android:paddingTop="15dp"
        android:textColor="#5c5966"
        android:text="@string/btnReplyText"/>

    <View 
        android:layout_height="fill_parent"
        android:layout_width="1dp"
        android:background="#505154" 
        android:layout_marginBottom="7dp" android:layout_marginTop="7dp"/>

    <Button
        android:id="@+id/btn_Delete"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:paddingBottom="15dp" android:paddingTop="15dp"
        android:textColor="#5c5966"
        android:background="@android:color/transparent"
        android:text="@string/btnDeleteText" />

    <View 
        android:layout_height="fill_parent"
        android:layout_width="1dp"
        android:background="#505154"
        android:text="@string/btnReplyText"
        android:layout_marginBottom="7dp" android:layout_marginTop="7dp" />

    <Button
        android:id="@+id/btn_Exit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_gravity="center"
        android:text="@string/btnExitText"
        android:paddingBottom="15dp" android:paddingTop="15dp"
        android:textColor="#5c5966"
        android:background="@android:color/transparent"/>
</LinearLayout>

All you have to do is change the colours and text to suit your own background. All the best!

Anirudh
  • 2,080
  • 5
  • 21
  • 34