如何在底部导航栏中添加一行

时间:2021-01-27 00:11:56

标签: android android-navigation

我想在导航栏顶部添加一条与此处图像中的内容类似的线(除了这不是导航栏)。Line

我该怎么做呢?我需要添加线视图吗?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:id="@+id/tab_contents"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottom_nav"
        android:layout_marginTop="0dp"
        android:layout_marginBottom="0dp">
    </ScrollView>


    <LinearLayout
        android:id="@+id/bottom_nav"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@color/white"
        android:orientation="horizontal">

        <Button
            android:id="@+id/nav_button1"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            style="?android:attr/borderlessButtonStyle"
            android:text="Home"/>

        <Button
            android:id="@+id/nav_button2"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            style="?android:attr/borderlessButtonStyle"
            android:text="Search"/>
    </LinearLayout>

</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

添加一个高度为 1db 或 2db 的单个视图并将其与底部视图的顶部对齐

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:id="@+id/tab_contents"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottom_nav"
        android:layout_marginTop="0dp"
        android:layout_marginBottom="0dp"></ScrollView>


    <LinearLayout
        android:id="@+id/bottom_nav"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@color/white"
        android:orientation="horizontal">

        <Button
            android:id="@+id/nav_button1"
            style="?android:attr/borderlessButtonStyle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Home" />

        <Button
            android:id="@+id/nav_button2"
            style="?android:attr/borderlessButtonStyle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Search" />
    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:layout_alignTop="@+id/bottom_nav"
        android:background="#C5C5C5" />


</RelativeLayout>