【问题标题】:Android bottom navigation view show text on the side of the iconAndroid底部导航视图在图标侧面显示文本
【发布时间】:2020-10-26 05:13:59
【问题描述】:

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

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

【问题讨论】:

    标签: android android-jetpack android-bottomnavigationview


    【解决方案1】:

    如何处理

    我认为通过创建自己的视图或片段可以更轻松地处理此问题。例如,您可以创建一个片段,并在此片段的布局中根据需要显示图标和文本。它会给你更多的力量来定制它。

    其他人正在使用什么

    我们不知道“City matter”是用什么方式来提供这个底栏的,也许他们已经实现了他们自己的自定义视图。

    这是一个简单的活动示例,您可以根据需要使用底栏:

    <?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>
    

    希望对你有帮助!

    【讨论】:

      猜你喜欢
      • 2019-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多