使用分隔符在Android xml中添加无边框按钮

使用分隔符在Android xml中添加无边框按钮,android,android-layout,android-xml,Android,Android Layout,Android Xml,我试图遵循Android团队在本文档中制定的指导原则: 根据文档,我应该使用这些框架资源。 这是我的代码,但没有显示任何边框。有什么想法吗 <LinearLayout android:id="@+id/buttonLayout" style="?android:buttonBarButtonStyle" android:layout_width="fill_parent" android:l

我试图遵循Android团队在本文档中制定的指导原则:

根据文档,我应该使用这些框架资源。

这是我的代码,但没有显示任何边框。有什么想法吗

<LinearLayout
            android:id="@+id/buttonLayout"
            style="?android:buttonBarButtonStyle"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:divider="?android:dividerVertical"
            android:orientation="horizontal"
            android:showDividers="middle" >

            <Button
                android:id="@+id/button1"
                style="?android:buttonBarButtonStyle"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Test" />

            <Button
                android:id="@+id/button2"
                style="?android:buttonBarButtonStyle"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Test" />
        </LinearLayout>

注意:我知道有一个问题,但我的资源似乎是最近的,但谷歌团队提出的解决方案不起作用。

预览

您无需使用仅具有视图颜色的按钮即可创建此视图。请尝试此操作

<LinearLayout
        android:id="@+id/bottom_bar"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:layout_alignParentBottom="true"
        android:background="#2B1B17" >

        <TextView
            android:id="@+id/tv_cancel"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="Cancel"
            android:textColor="@drawable/text_changepassword_selector"
            android:textSize="19sp" />

        <View
            style="@style/Divider"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp" />

        <TextView
            android:id="@+id/tv_apply"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="Select"
            android:textColor="@drawable/text_changepassword_selector"
            android:textSize="19sp" />
    </LinearLayout>

线性布局中的样式错误。应该是

style="?android:buttonBarStyle"
不是

style="?android:buttonBarButtonStyle"
例如:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/buttonLayout"
    style="?android:attr/buttonBarStyle"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Test"/>

    <TextView
        android:layout_height="wrap_content"
        android:text="TextView (Place Holder)"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_width="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="15dp"/>

    <LinearLayout
        style="?android:attr/buttonBarStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <Button
            android:id="@+id/button2"
            style="?android:attr/buttonBarButtonStyle"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Test"/>

        <Button
            android:id="@+id/button3"
            style="?android:attr/buttonBarButtonStyle"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Test"/>
    </LinearLayout>
</LinearLayout>

示例2(列表视图):


上边框是一个“分隔符”,用于分隔线性布局中的元素。如果按钮栏位于垂直布局的底部,则必须在垂直布局中激活分隔符的显示。通常,我通过添加以下属性来实现:

android:showDividers="middle"
android:divider="?android:dividerHorizontal" 
android:dividerPadding="8dp"
完整布局代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="?android:dividerHorizontal"
    android:dividerPadding="8dp"
    android:orientation="vertical"
    android:showDividers="middle" >

    <TextView
        android:id="@+id/url"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:text="dummyText" />

    <LinearLayout
        style="?android:buttonBarStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button1"
            style="?android:buttonBarButtonStyle"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button1" />

        <Button
            android:id="@+id/button2"
            style="?android:buttonBarButtonStyle"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button2" />
    </LinearLayout>

</LinearLayout>

我在文档之后遇到了同样的问题。当按钮上没有其他视图时,User305552提供的解决方案将提供中间分隔符,但没有顶部分隔符。 尝试:



谢谢,但根据谷歌的说法,我不需要使用额外的
,这就是我提出这个问题的原因。不过,我很欣赏一个工作环境。@EGHDK-Hmmm我就是这样做的。如果您不使用@Brontok就找到了它,那就太好了。到目前为止,它与用户305552提供的答案一起工作。我仍然在想,是否有一个解决方案,在按钮顶部的除法器以及。啊哈。显然,我在这方面工作太久了。这将潜水员添加到了中间,但如何在按钮顶部添加除法器?对此不太确定,显然我从未使用过它。但是我想我可以试着把它弄得乱七八糟。好吧,翻了翻文档,似乎只有在相同的布局中,按钮顶部有更多的内容时,顶部边框才会出现。嗯,我在这些按钮顶部有一个列表视图,它们不会显示。你能发布一个像你提到的那样有效的例子吗?你可以这样做…(例子2)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="?android:dividerHorizontal"
    android:dividerPadding="8dp"
    android:orientation="vertical"
    android:showDividers="middle" >

    <TextView
        android:id="@+id/url"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:text="dummyText" />

    <LinearLayout
        style="?android:buttonBarStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button1"
            style="?android:buttonBarButtonStyle"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button1" />

        <Button
            android:id="@+id/button2"
            style="?android:buttonBarButtonStyle"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button2" />
    </LinearLayout>

</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="vertical">

  <View 
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="?android:attr/dividerVertical"/>

    <LinearLayout style="?android:buttonBarStyle"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <Button style="?android:buttonBarButtonStyle"
            android:id="@+id/back"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:text="@string/back"/>
        <Button style="?android:buttonBarButtonStyle"
            android:id="@+id/next"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:text="@string/next"/>
    </LinearLayout>
</LinearLayout>