android - 如何在底部导航栏上绘制顶部边框

标签 android xml android-layout navbar

我正在尝试在我的 Android 应用程序底部导航栏的顶部绘制边距。这就是我现在拥有的:

this is my app now

我想要实现的是底部栏上的黑色顶部边框。我使用拆分操作栏创建了它。这是我的 xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
        parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
        <item name="android:actionBarSplitStyle">@style/MyBottomBar</item>

    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar"
        parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="@android:background">@color/white</item>
        <item name="@android:textColor">@color/black</item>
    </style>

    <!--bottom bar style-->
    <style name="MyBottomBar">
        <item name="android:backgroundSplit">@color/white</item>
    </style>

    <!-- ActionBar title text -->
    <style name="MyActionBarTextStyle"
        parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
            <item name="@android:textColor">@color/black</item>
    </style>

</resources>

我不知道我需要给底栏什么,Android 的文档也不是那么清楚。请帮帮我!谢谢大家!

最佳答案

您需要在 drawable 文件夹中创建一个新的 .xml 文件。您可以将其称为“bottom_navbar_background.xml”。像这样在文件上画一个矩形:

<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:bottom="1dp">
        <shape
            android:dither="true"
            android:shape="rectangle">
            <corners android:radius="2dp" />

            <solid android:color="@color/black" />
        </shape>
    </item>

    <item android:top="1dp">
        <shape
            android:dither="true"
            android:shape="rectangle">


            <solid android:color="@android:color/white" />

            <padding
                android:bottom="0dp"
                android:left="0dp"
                android:right="0dp"
                android:top="0dp" />
        </shape>
    </item>

</layer-list>

像这样把它作为 splitNavbar 自定义主题的背景:

<item name="android:backgroundSplit">@drawable/bottom_navbar_background</item>

等等:你的导航栏上有顶部边框!

关于android - 如何在底部导航栏上绘制顶部边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22899316/

相关文章:

android - CoordinatorLayout 和 ImageView 在滚动时调整宽度的问题

android - 防止多个版本的 Android 应用产生相同的服务

javascript - XSD 正则表达式 : empty string OR something else

php - 使用PHP导出XML,通过AJAX将其拉入DOM,但xml不可见

java - 使用三元返回带注释 @ColorInt android 的颜色资源

java - 用于 Android 应用程序开发的 JDK

java - 如何在 Java 中轻松更改 XML 文档的文档类型?

android - 使用xml进行布局有什么好处?

android - 如何以编程方式设置底部边距?

android - 如何定位径向渐变背景