我想在底部导航视图上设置指示器。您可以看到底部的橙色线
如何设置指示器?

我没有找到任何指标示例。
<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"/>
Run Code Online (Sandbox Code Playgroud) 我正在使用带有 afragment和 a的以下活动布局BottomNavigationView:
<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">
<fragment
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/fragment"
android:layout_weight="1"
android:name="androidx.navigation.fragment.NavHostFragment"
app:newGraph="@navigation/navigation_bottom"
app:defaultNavHost="true"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bottom_navigation_view"
app:menu="@menu/bottom_navigation_menu"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
在我的活动中,我正在尝试设置导航控制器,但出现以下错误:
无法解析方法“setupWithNavController(androidx.navigation.NavController)”
这是我尝试过的:
navController = Navigation.findNavController(this, R.id.fragment);
BottomNavigationView bnv = findViewById(R.id.bottom_navigation_view);
bnv.setupWithNavController(navController); //Error
NavigationUI.setupActionBarWithNavController(this, navController);
Run Code Online (Sandbox Code Playgroud)
我的依赖:
implementation 'android.arch.navigation:navigation-fragment:1.0.0-rc02'
implementation 'android.arch.navigation:navigation-ui:1.0.0-rc02'
Run Code Online (Sandbox Code Playgroud)
我该如何接线?谢谢!
我正在使用导航组件和底部导航
val navController = indNavController(R.id.nav_host_fragment)
bottom_navigation.inflateMenu(R.menu.bottom_navigation_menu)
bottom_navigation.setupWithNavController(navController)
Run Code Online (Sandbox Code Playgroud)
我面临下一个问题:
当在底部导航中选择一个项目时,就会加载一个片段。当我再次按下同一个项目时,问题就出现了,然后会加载一个新的片段,这根本没有意义。
示例: 1- 用户选择菜单项 A,然后加载 FragmentA。2- 用户再次选择菜单项 A,然后将加载一个新的 FragmentA,
我试图使用
bottom_navigation.setOnNavigationItemSelectedListener { }
Run Code Online (Sandbox Code Playgroud)
但是底部导航将无法与 navController 一起使用。
所以问题是:有一种方法可以处理这种情况,以便在用户已经在该屏幕上时再次加载新片段?
我试图在底部导航视图中添加超过 5 个项目,但它导致膨胀错误。
我刚刚实现了底部导航(AS的默认设置-文件->新建->活动->底部导航活动),除了顶部的空格外,其他都不错nav_host_fragment。

由于它是在ConstraintLayout中生成的,因此我尝试清除约束并使用设置最高约束parent,将其设置margin为'0dp'并设置height为match_constraint。
我未能成功删除约束,并反复尝试。
我用过Clean Project。
我改为RelativeLayout并设置如下参数:
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_above="@+id/nav_view"
app:defaultNavHost="true"
app:navGraph="@navigation/mobile_navigation" />
Run Code Online (Sandbox Code Playgroud)
但是nav_host_fragment顶部之间的空间仍然存在。
这是lyout文件:
<RelativeLayout 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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="?android:attr/windowBackground"
app:menu="@menu/bottom_nav_menu" />
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_above="@+id/nav_view"
app:defaultNavHost="true"
app:navGraph="@navigation/mobile_navigation" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 当我单击之前选择的项目时,我正在使用带有 android 导航组件的底部导航,系统创建该片段的新实例,在视图中替换它并删除最后一个片段。我想防止重新创建片段并忽略用户点击
这是我的菜单:
<item
android:id="@+id/historyFragment"
android:title="@string/main_records"
android:icon="@drawable/ic_records"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/mainFragment"
android:icon="@drawable/ic_pulse"
android:title="@string/main_measure" />
<item
android:id="@+id/settingFragment"
android:icon="@drawable/ic_settings"
android:title="@string/main_setting"
app:showAsAction="ifRoom"/>
Run Code Online (Sandbox Code Playgroud)
java android bottomnavigationview android-architecture-navigation
我只需要底部导航栏项中的标签,但我找不到删除它们的方法。
您可以使用showSelectedLabels和showUnselectedLabels设置为 false隐藏标签,但图标没有等效项。
构造函数:
BottomNavigationBar({
Key key,
@required this.items,
this.onTap,
this.currentIndex = 0,
this.elevation = 8.0,
BottomNavigationBarType type,
Color fixedColor,
this.backgroundColor,
this.iconSize = 24.0,
Color selectedItemColor,
this.unselectedItemColor,
this.selectedIconTheme = const IconThemeData(),
this.unselectedIconTheme = const IconThemeData(),
this.selectedFontSize = 14.0,
this.unselectedFontSize = 12.0,
this.selectedLabelStyle,
this.unselectedLabelStyle,
this.showSelectedLabels = true,
bool showUnselectedLabels,
})
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我创建了一个带有浮动按钮的引导菜单栏布局,并将其包含在我的主要活动中,并且我还在我的主要活动中放置了一个回收器视图
我只是添加了 100 个项目以显示在我的回收站视图中以检查它是否在运行我的应用程序时它是否正常工作,最后一个项目的回收站视图隐藏在底部菜单栏中如何解决这个问题
这是我所说的示例图像
活动_main.xml
<include
layout="@layout/toolbar"
android:id="@+id/toolbar"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
/>
<include
android:id="@+id/bottom_nav"
layout="@layout/bottom_menu_bar"
/>
Run Code Online (Sandbox Code Playgroud)
底部菜单栏。xml
<?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"
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="@menu/bottom_nav_menu" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_padding"
android:src="@drawable/ic_add"
android:tint="@color/colorWhite"
app:backgroundTint="@color/colorPrimary"
app:layout_anchor="@id/bottom_nav"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:elevation="@dimen/floating_b_ele"
android:clickable="true"
android:focusable="true"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)