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

EGH*_*HDK 5 android android-layout android-xml

我正在尝试遵循 Android 团队从本文档中制定的指南:

https://docs.google.com/file/d/0Bz3qX4EBhUvwZWlHekI3Y0wxSUk/edit

根据文档,我应该使用这些框架资源。 在此处输入图片说明

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

<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>
Run Code Online (Sandbox Code Playgroud)

注意:我知道有一个类似/确切的问题,但我的资源似乎更新了,但 Google 团队提供的解决方案不起作用。

use*_*552 3

您在 LinearLayout 中的样式错误。它应该是

style="?android:buttonBarStyle"
Run Code Online (Sandbox Code Playgroud)

不是...

style="?android:buttonBarButtonStyle"
Run Code Online (Sandbox Code Playgroud)

例子:

<?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>
Run Code Online (Sandbox Code Playgroud)

示例 2(列表视图):

<?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">
    <ListView
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_weight="1.0"/>
    <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>
Run Code Online (Sandbox Code Playgroud)