我只是检查设计指南并想知道无边界按钮。这是正常的Button小部件,但你添加了一个自定义(Android默认)样式?如何制作这些无边界按钮?
此处链接到设计指南:
只需在你的Button
代码中添加以下样式属性即可:
style="?android:attr/borderlessButtonStyle"
参考:http : //developer.android.com/guide/topics/ui/controls/button.html#Borderless
为了澄清一些混淆:
这通过2个步骤完成:将按钮背景属性设置为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>