android - Android底部导航视图在图标侧面显示文本
问题描述
我想在图标右侧显示底部栏文本,例如 City Mapper。我目前使用 Android 默认组件实现了我的第一个版本
在这里提出了这个问题,但没有找到解决方案,并且有人评论说这是不可能的。如果 City Mapper 正在这样做,那么它应该是可能的。我该怎么做?
解决方案
如何处理
我认为通过创建自己的视图或片段来处理这个问题会更容易。例如,您可以创建一个片段,并在此片段的布局中根据需要显示图标和文本。它会给你更多的权力来定制它。
其他人正在使用什么
我们不知道“城市事务”使用什么方式来提供这个底栏,也许他们已经实现了他们自己的自定义视图。
<?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>
我希望它会帮助你!
推荐阅读
- github - 如何从 Github API V3 上的发布或标签获取提交 SHA
- c - C中的快速排序——指针和内存
- django - 从 django 发送邮件失败
- javascript - 填写字段时使用 JavaScript 弹出 SweetAlert 消息
- sql - SQL Server 案例更新
- java - 不可分配给 android.app.application
- c - 如何修复“postgres.h”文件未找到问题?
- git - 重置命令后强制推送 git 提交不起作用
- react-native - undefined 不是对象(评估“response.data”)
- php - 不能在 Eloquent Query Builder 宏中使用“with”