为了账号安全,请及时绑定邮箱和手机立即绑定

如何创建标准的无边框按钮(如上述设计指南中所述)?

如何创建标准的无边框按钮(如上述设计指南中所述)?

宝慕林4294392 2019-10-23 15:28:17
我只是查看设计指南,想知道无边界按钮。我凝视了一下,试图在源中查找,但我自己无法将其组合在一起。这是普通的Button小部件,但是您添加了自定义(Android默认)样式?如何制作这些无边界按钮(当然您可以将背景设置为空,但是我没有分隔线)?这里链接到设计指南:http://developer.android.com/design/building-blocks/buttons.htmlhttp://developer.android.com/guide/topics/ui/controls/button.html#Borderless
查看完整描述

3 回答

?
慕妹3242003

TA贡献1824条经验 获得超6个赞

为了消除一些混乱:


这需要2个步骤:将button background属性设置为android:attr / selectableItemBackground会创建一个带有反馈但没有背景的按钮。


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

将无边界按钮与其余布局分开的行是通过背景为android:attr / dividerVertical的视图完成的


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

为了更好地理解,此处是屏幕底部的“确定” /“取消无边界”按钮组合的布局(如上图所示)。


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


查看完整回答
反对 回复 2019-10-23
?
繁花如伊

TA贡献2012条经验 获得超12个赞

对于那些想要无边界按钮但在单击时仍保持动画效果的人。在按钮中添加它。


style="?android:attr/borderlessButtonStyle"

如果需要分隔线/它们之间的线。将其添加到线性布局中。


style="?android:buttonBarStyle"

摘要


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

   android:layout_width="fill_parent"

   android:layout_height="wrap_content"

   android:orientation="horizontal"

   style="?android:buttonBarStyle">


    <Button

        android:id="@+id/add"

        android:layout_weight="1"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:text="@string/add_dialog" 

        style="?android:attr/borderlessButtonStyle"

        />


    <Button

        android:id="@+id/cancel"

        android:layout_weight="1"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:text="@string/cancel_dialog" 

        style="?android:attr/borderlessButtonStyle"

        />


</LinearLayout>


查看完整回答
反对 回复 2019-10-23
  • 3 回答
  • 0 关注
  • 323 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信