gpt4 book ai didi

android - 如何在 BottomNavigationView 中设置指标?

转载 作者:行者123 更新时间:2023-12-04 23:43:45 31 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Badge on BottomNavigationView

(4 个回答)


2年前关闭。




我想在底部导航 View 上设置指示器。你可以在底部看到橙色线
如何设置指标?

enter image description here
我没有找到任何指标示例。

 <android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@drawable/bottom_navigation_bg"
app:labelVisibilityMode="unlabeled"
app:menu="@menu/bottom_menu_main"/>

最佳答案

我之前的回答提供了很大的灵 active ,并且在选定的状态之间很好地动画,但涉及相对大量的代码。没有动画的更简单的解决方案是使用 itemBackground BottomNavigationView 的属性:

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

<androidx.viewpager2.widget.ViewPager2
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemBackground="@drawable/bottom_nav_tab_background"
android:layout_gravity="bottom"
app:menu="@menu/menu_bottom_nav" />

</LinearLayout>

bottom_nav_tab_background
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<layer-list>
<item android:gravity="bottom">
<shape android:shape="rectangle">
<size android:height="4dp" />
<solid android:color="?attr/colorPrimary" />
</shape>
</item>
</layer-list>
</item>
</selector>

关于android - 如何在 BottomNavigationView 中设置指标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54741711/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com