升级依赖后:
'com.google.android.material:material:xxx'
从1.4.0到1.5.0,导航项文本以某种方式从锚定在图标下方更改为图标上方:
从:
到:
这是一个功能还是一个错误,有修复吗?
我有一个非常简单的应用程序,由三个片段和一个底部导航栏组成,是通过使用 Android Studio 中的“新项目 -> 底部导航活动”创建的。第一个片段包含一个按钮,它应该将我带到第二个片段,就像单击底部导航栏的中间按钮一样。

有没有一个“标准”的方法来做到这一点?
我努力了:
launch(...)导航组件,该组件似乎使用自己的后堆栈启动片段并破坏底部导航。setSelectedItemId(...),这要么导致异常,要么以不同的方式破坏底部导航。android bottomnavigationview android-bottomnav android-architecture-navigation
我将导航库从2.3.5更新到2.4.2。更新后我开始收到此错误:java.lang.IllegalArgumentException: No destination with ID XXX is on the NavController's back stack. The current destination is null。执行以下步骤后会发生错误:FirstFragment -> SecondFragment [with another BottomNavigationView] -> ThirdFragment -> SecondFragment [crash]
我将尝试描述我正在做的事情:
我有两个片段BottomNavigationView。
class MainBottomNavFragment : Fragment() {
private lateinit var navController: NavController
override fun onStart() {
super.onStart()
if (!::navController.isInitialized) {
navController =
Navigation.findNavController(requireActivity(), R.id.mainBottomNavHostFragment)
}
binding.bottomNavigation.setupWithNavController(navController)
}
}
Run Code Online (Sandbox Code Playgroud)
布局
<?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">
<fragment
android:id="@+id/mainBottomNavHostFragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="false" …Run Code Online (Sandbox Code Playgroud) 由于右下角的曲线,我想将脚手架主体延伸到 AppBar 后面:
我试过Modifier.offset(y = (-25).dp)。它工作正常,但 BG 图像不再填充底部导航栏后面的区域:
Scaffold( topBar = { ... }, )
{ padding ->
Box(
Modifier.padding(padding),
contentAlignment = Alignment.TopCenter
) {
Box(
modifier = Modifier
.fillMaxSize()
.offset(y = (-25).dp), // BG image behind AppBar
) {
Image(
modifier = Modifier.fillMaxSize(),
painter = painterResource(R.drawable.bg),
contentDescription = null,
contentScale = ContentScale.FillBounds
)
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能两者兼得?
我创建一个底部导航视图。我尝试获取底部导航视图的高度。材料设计表明高度应为56dp。我不想使用硬编码的值,因为我不确定该值不会更改。我如何像获取状态栏的高度那样以编程方式获取视图的尺寸。
int resourceId =getResources().getIdentifier("status_bar_height","dimen","android");
if (resourceId > 0) {
height = getResources().getDimensionPixelSize(resourceId);
}
Run Code Online (Sandbox Code Playgroud) android android-layout android-navigation bottomnavigationview android-bottomnav
我试图将底部导航视图中的图标调低。例如,现在它们像这样按在顶行上。

我如何降低图标?我希望它们在底部导航视图中垂直居中。
xml:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.jchousurface.mastertrack.homescreen">
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#FFFFFF"
app:menu="@menu/navigation" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我一直在使用BottomNavigationBar,但是我无法在onTap回调BottomNavigationBar之外以编程方式选择Tab.
以下代码使用onTap回调[哪个有效]
return new BottomNavigationBar(
items: <BottomNavigationBarItem>[
_bottomNavigationItem(Icons.account_circle, DrawerTitles.CONTACTS),
_bottomNavigationItem(Icons.delete, DrawerTitles.DELETED_CONTACTS),
_bottomNavigationItem(Icons.list, DrawerTitles.LOGS),
],
onTap: (int index) {
setState(() {
navigationIndex = index;
switch (navigationIndex) {
case 0:
handleBottomNavigationBarClicks(DrawerTitles.CONTACTS);
break;
case 1:
handleBottomNavigationBarClicks(DrawerTitles.DELETED_CONTACTS);
break;
case 2:
handleBottomNavigationBarClicks(DrawerTitles.LOGS);
break;
}
});
},
currentIndex: navigationIndex,
fixedColor: Colors.blue[400],
type: BottomNavigationBarType.fixed,
);
Run Code Online (Sandbox Code Playgroud)
但我想更改onTap回调之外的选项卡?
我尝试在onTap callBack之外更改BottomNavigatioBar使用的索引,但它没有用.
这是我试过的 -
void changeTabs(int tabIndex) {
setState(() {
navigationIndex = tabIndex;
});}
Run Code Online (Sandbox Code Playgroud)
有没有办法改变标签?
这是代码的要点
https://gist.github.com/harsh159357/62f338a196b0e5edad7aed5017dae3e5
我目前正在和BottomNavigationView和一起工作FloatingActionButton。我要实现的是以下设计:
而我尝试了:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
app:layout_insetEdge="bottom"
tools:context=".activity.BottomNavPrimary">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottomNavPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:layout_insetEdge="bottom"
android:background="?android:attr/windowBackground"
app:menu="@menu/bottom_nav_primary"></android.support.design.widget.BottomNavigationView>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud) android android-layout floating-action-button android-coordinatorlayout bottomnavigationview