Android borderless buttons

℡╲_俬逩灬. 提交于 2020-01-22 05:14:06

问题


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

回答1:


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

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



回答2:


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




回答3:


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




回答4:


This code will remove all background for a button:

android:background="@android:color/transparent"



回答5:


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!



来源:https://stackoverflow.com/questions/9695115/android-borderless-buttons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!