标签: bottomnavigationview

BottomNavigationView 图标上方显示的导航项目文本

升级依赖后:

'com.google.android.material:material:xxx'

1.4.01.5.0,导航项文本以某种方式从锚定在图标下方更改为图标上方:

从:

在此输入图像描述

到:

在此输入图像描述

这是一个功能还是一个错误,有修复吗?

android bottomnavigationview

6
推荐指数
2
解决办法
2623
查看次数

使用底部导航和导航组件在按钮单击上切换选项卡

我有一个非常简单的应用程序,由三个片段和一个底部导航栏组成,是通过使用 Android Studio 中的“新项目 -> 底部导航活动”创建的。第一个片段包含一个按钮,它应该将我带到第二个片段,就像单击底部导航栏的中间按钮一样。

带按钮的片段

有没有一个“标准”的方法来做到这一点?

我努力了:

  • 使用launch(...)导航组件,该组件似乎使用自己的后堆栈启动片段并破坏底部导航。
  • 以不同的方式使用setSelectedItemId(...),这要么导致异常,要么以不同的方式破坏底部导航。

在这篇文章中,有人问了完全相同的问题,但它被标记为重复。我找不到答案,特别是关于导航组件。

android bottomnavigationview android-bottomnav android-architecture-navigation

6
推荐指数
1
解决办法
9856
查看次数

添加多个后退堆栈支持后 Android jetpack 导航不起作用 [2.4.+]

我将导航库从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)

android bottomnavigationview android-jetpack-navigation

6
推荐指数
0
解决办法
713
查看次数

Android Jetpack Compose 中 AppBar 后面的脚手架主体?

由于右下角的曲线,我想将脚手架主体延伸到 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)

在此输入图像描述

我怎样才能两者兼得?

appbar offset bottomnavigationview android-jetpack-compose

6
推荐指数
2
解决办法
4054
查看次数

Android-如何获取bottomnavigationview的高度

我创建一个底部导航视图。我尝试获取底部导航视图的高度。材料设计表明高度应为56dp。我不想使用硬编码的值,因为我不确定该值不会更改。我如何像获取状态栏的高度那样以编程方式获取视图的尺寸。

int resourceId =getResources().getIdentifier("status_bar_height","dimen","android");
if (resourceId > 0) {
     height = getResources().getDimensionPixelSize(resourceId);
} 
Run Code Online (Sandbox Code Playgroud)

android material-design bottomnavigationview

5
推荐指数
1
解决办法
8164
查看次数

5
推荐指数
1
解决办法
1万
查看次数

删除底部导航视图中图标的填充

我试图将底部导航视图中的图标调低。例如,现在它们像这样按在顶行上。

在这里查看图片

我如何降低图标?我希望它们在底部导航视图中垂直居中。

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)

android navigationview bottomnavigationview

5
推荐指数
1
解决办法
2483
查看次数

Android:从底部导航中删除阴影

将容器放置在我的底部导航下方时,即使在向容器添加内容之后,它也会被导航中的灰色阴影部分覆盖.如何删除阴影? 截图

android android-layout bottomnavigationview

5
推荐指数
2
解决办法
2405
查看次数

如何以编程方式选择Flutter中的BottomNavigationBar选项卡而不是内置onTap回调?

我一直在使用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

dart flutter bottomnavigationview material-components

5
推荐指数
3
解决办法
3782
查看次数

晶圆厂底部导航

我目前正在和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

5
推荐指数
3
解决办法
9858
查看次数