Android底部导航视图在图标侧面显示文本

问题描述

我想在图标的右侧显示底部的条形文字,例如City Mapper。我目前已经使用Android默认组件实现了第一个版本

City Mapper bottom nav

有人问这个问题here,但未找到解决方案,有人评论说这是不可能的。如果City Mapper正在这样做,那应该是可能的。我该怎么办?

解决方法

如何处理

我认为通过创建自己的视图或片段可以更轻松地解决此问题。例如,您可以创建一个片段,并在该片段的布局中根据需要显示图标和文本。它将为您提供更多定制功能。

其他人正在使用什么

我们不知道“城市问题”是通过什么方式提供此底线的,也许他们已经实现了自己的自定义视图。

以下是一个简单活动的示例,该活动带有您希望的底部条形: Simple activity with a bottom bar created with a Linear Layout.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#BFBFBF"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


    <LinearLayout
        android:background="#FFF"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="parent">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center">

            <ImageView
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:src="@android:drawable/ic_menu_search" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Search" />

        </LinearLayout>

        <View
            android:layout_width="1dp"
            android:background="#ACACAC"
            android:layout_marginVertical="5dp"
            android:layout_height="match_parent"/>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center">

            <ImageView
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:src="@android:drawable/ic_menu_search" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Search" />

        </LinearLayout>

    </LinearLayout>
    
</androidx.constraintlayout.widget.ConstraintLayout>

希望它能对您有所帮助!

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...