如何创建标准的无边框按钮(如在设计理念为指导提到的)?边框、如在、设计理念、按钮

2023-09-11 12:40:43 作者:甜软奶喘~

我只是检查了设计指南和想知道的无边框按钮。 我瞪大眼睛,并试图找到在源代码中,但不能由我自己把它在一起。 这是正常的按钮组件,但是你添加自定义(Android的默认值)的风格? 如何让这些无国界的按钮(当然你也可以将背景设置为空,但我没有分频器)?

下面链接的设计准则:

http://developer.android.com/design/building-blocks/buttons.html http://developer.android.com/guide/topics/ui/controls/button.html#Borderless

解决方案

要清除一些混乱:

这是在2步:按钮背景属性设置为机器人:ATTR / selectableItemBackground 创建您的反馈,但没有背景的一个按钮

 安卓背景=机器人:ATTR / selectableItemBackground
 
html 页面中有很多超链接,把其中一个超链接改为button样式,最好能在一行内实现,比如 style .... ,高手赐教 越简单越好用分越高

ATTR / dividerVertical

该行从静止你布局由视图与背景机器人进行划分无边框按钮

 安卓背景=机器人:ATTR / dividerVertical
 

为了更好地理解这里是一个正常的布局/取消无边框按钮的组合在屏幕底部(如在右上图)。

 < RelativeLayout的
        机器人:layout_width =match_parent
        机器人:layout_height =48dp
        机器人:layout_alignParentBottom =真正的>
        <查看
            机器人:layout_width =match_parent
            机器人:layout_height =1dip
            机器人:layout_marginLeft =4dip
            机器人:layout_marginRight =4dip
            机器人:背景=机器人:ATTR / dividerVertical
            机器人:layout_alignParentTop =真/>
        <查看
            机器人:ID =@ + ID / ViewColorPickerHelper
            机器人:layout_width =1dip
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_alignParentTop =真
            机器人:layout_alignParentBottom =真
            机器人:layout_marginBottom =4dip
            机器人:layout_marginTop =4dip
            机器人:背景=机器人:ATTR / dividerVertical
            机器人:layout_centerHorizo​​ntal =真/>
        <按钮
            机器人:ID =@ + ID / BtnColorPickerCancel
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_alignParentLeft =真
            机器人:layout_alignParentTop =真
            机器人:layout_toLeftOf =@ ID / ViewColorPickerHelper
            机器人:背景=机器人:ATTR / selectableItemBackground
            机器人:文本=@安卓串/取消
            机器人:layout_alignParentBottom =真/>
        <按钮
            机器人:ID =@ + ID / BtnColorPickerOk
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =match_parent
            机器人:layout_alignParentRight =真
            机器人:layout_alignParentTop =真
            机器人:背景=机器人:ATTR / selectableItemBackground
            机器人:文本=@安卓串/ OK
            机器人:layout_alignParentBottom =真
            机器人:layout_toRightOf =@ ID / ViewColorPickerHelper/>
    < / RelativeLayout的>
 

I was just checking the design guidelines and wondering about the borderless buttons. I goggled and tried to find in the source but can't bring it together by myself. Is this the normal Button widget but you add a custom (Android default) style? How to make these borderless buttons (of course you can set the background to empty, but then I don't have the divider)?

Here links to the design guidelines:

http://developer.android.com/design/building-blocks/buttons.html http://developer.android.com/guide/topics/ui/controls/button.html#Borderless

解决方案

To clear some confusion:

This is done in 2 steps: Setting the button background attribute to android:attr/selectableItemBackground creates you a button with feedback but no background.

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

The line to divide the borderless button from the rest of you layout is done by a view with the background android:attr/dividerVertical

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

For a better understanding here is a layout for a OK / Cancel borderless button combination at the bottom of your screen (like in the right picture 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>