bottomnavigationview 相关问题

与底部导航栏相关的问题。底部导航栏菜单项标题,图标,填充内容和启用状态相关问题。底部导航栏项目单击侦听器,项目背景资源,项目文本颜色,膨胀菜单,最大项目计数。底部导航栏是材料设计底部导航的实现。

如何更改 Kotlin 中 android studio 底部导航栏中所选项目周围的颜色?

我找不到更改底部导航栏中所选项目周围颜色的方法。就像下图中的紫色一样。 我尝试更改原色(

回答 2 投票 0

Android 底部导航视图占用太多高度

我没有使用任何样式/主题或任何复杂的自定义,但底部导航视图占据了意想不到的高度, 我使用 wrap_content 作为高度,因此得到以下输出: 我没有使用任何样式/主题或任何复杂的自定义,但底部导航视图正在采取意外的高度, 我使用 wrap_content 作为高度,因此得到以下输出: <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottom_nav" android:layout_width="match_parent" **android:layout_height="wrap_content"** app:labelVisibilityMode="selected" app:menu="@menu/bottom_nav_menu" /> 当使用固定高度时,即?attr/actionbarsize我得到以下输出(所有图标/标签折叠): 代码: <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottom_nav" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:labelVisibilityMode="selected" app:menu="@menu/bottom_nav_menu" /> 布局完整代码: <?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/main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".AppInstalledCheckActivity" android:background="#FFEB3B"> <EditText android:id="@+id/edittextPackageName" android:layout_width="match_parent" android:layout_height="60dp" android:hint="Enter Package Name" /> <Button android:id="@+id/buttonCheckInstalled" android:layout_width="match_parent" android:layout_height="45dp" android:text="Enter Package Name" /> <androidx.fragment.app.FragmentContainerView android:id="@+id/nav_host_fragment" android:name="androidx.navigation.fragment.NavHostFragment" android:layout_width="match_parent" android:layout_height="400dp" app:navGraph="@navigation/navgraph" /> <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottom_nav" android:layout_width="match_parent" android:layout_height="wrap_content" app:labelVisibilityMode="selected" app:menu="@menu/bottom_nav_menu" /> </LinearLayout> 我希望它与工具/操作栏具有相同或相似的高度。 你需要改变 <androidx.fragment.app.FragmentContainerView android:id="@+id/nav_host_fragment" android:name="androidx.navigation.fragment.NavHostFragment" android:layout_width="match_parent" **android:layout_height="400dp"** app:navGraph="@navigation/navgraph" /> 到 **android:layout_height="match_parent"**

回答 1 投票 0

(BottomNavigationView) 此组件上的样式要求您的应用程序主题为 Theme.AppCompat (或后代)

在我的应用程序布局中使用 com.google.android.material.bottomnavigation.BottomNavigationView 时,出现以下错误: 引起原因:android.view.InflateException:com.e 中的二进制 XML 文件第 25 行...

回答 1 投票 0

为什么我的底部导航栏下方有一个空格?

底部导航图标下方有一个很大的空间。我想解决它很长时间但无法解决。 这是标记: 底部导航图标下方有一个很大的空间。我尝试了很长时间但无法解决。 这是标记: <FrameLayout android:layout_width="0dp" android:layout_height="0dp" app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> </FrameLayout> <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottomNavigationView" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:menu="@menu/bottom_nav_menu" /> 我想解决它。 从 java 活动中删除此代码解决了我的问题 ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); return insets; });

回答 1 投票 0

Flutter 中的某些设备中底部导航栏需要更高的高度

我正在 Flutter 应用程序中开发 BottomNavigationBar,但我注意到,它在某些手机中需要更高的高度,例如某些 Iphone、三星 Galaxy S23 等。 我尝试将 Container 或 SizeBox 与 pre-

回答 1 投票 0

Flutter 中 BottomAppBar 的异常行为

我遇到了 FloatingActionButton 和 BottomAppBar 在此处输入图像描述的异常行为, 我面临的问题是凹口不在中心,而且行的槽...

回答 1 投票 0

底部导航如何从片段内部更改片段

我有一个包含 3 个片段的底部导航视图 我想从片段 1 内部而不是从活动中将片段 1 更改为片段 2 有谁知道怎么做吗?

回答 2 投票 0

如何让底部导航Activity通过滑动改变片段?

我使用适当的 android studio 模板创建了一个新活动:新建->活动->底部导航活动。我向 AppBarConfiguration 添加了 5 个片段,除了一个之外一切正常......

回答 2 投票 0

NullPointerException:尝试在空对象引用上调用虚拟方法“int android.view.ViewGroup.getPaddingBottom()”

当我尝试将菜单膨胀到 BottomNavigationView 但同样崩溃时崩溃。我已将材料设计库从 'com.google.android.material:material:1.2.1' 更新为 'com.google.andr...

回答 1 投票 0

BottonNavigationView 图标在按下后不会改变

我正在使用导航组件作为底部导航组件。 底部导航栏.setupWithNavController(navController) 现在一切正常,但是当我按下后退按钮时,它会返回到...

回答 3 投票 0

如何使用BottomNavigationView的material3设计

我正在使用BottomNavigationView 我正在使用 BottomNavigationView <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottomNavigationView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" app:menu="@menu/bottom_nav_menu" /> //build.gradele implementation "androidx.compose.material:material-icons-extended:1.5.0" implementation 'androidx.compose.material:material:1.5.0' 但设计源自Material2? 两种设计都使用相同的视图实现,您只需对其应用一些material3主题,例如 <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottomNavigationView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" app:menu="@menu/bottom_nav_menu" android:theme="@style/Theme.Material3.DayNight"/>

回答 1 投票 0

flutter:使用 svg 来实现持久的导航栏项目

列表_navbarItems = [ 持久底部导航栏项目( 图标:SvgPicture.asset( '图片/sofa_home.svg', 宽度:22, ), activeColorPrimary:ColorsConst.yellow, 标题:“家”, inactiveColorPrimary:ColorsCo...

回答 1 投票 0

图标不显示其原始设计颜色

我在主活动视图上实现了底部导航,并在其中设置了四个图标,其中一些是橙色阴影,一个有两种颜色:洋红色和橙色。有什么东西干扰了他们

回答 1 投票 0

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

我有一个非常简单的应用程序,由三个片段和一个底部导航栏组成,是通过使用 Android Studio 中的“新建项目 -> 底部导航活动”创建的。第一个片段

回答 3 投票 0

如何在flutter中将小部件定位到导航栏底部?

我需要将高度为 5.0 且宽度无限大的容器放置在底部导航栏项目中的底部。但是当前位置和底部导航有差距...

回答 2 投票 0

撰写底部导航填充

我正在尝试在 BottomNavigation 可组合项上正确应用底部窗口插图。我有一个边到边的脚手架,它看起来像这样: 使用时: 修改器.navigationBarsPadding() 在底部

回答 2 投票 0

如何为Android底部导航栏中的图标添加背景?

我只想添加图标背景而不是所有项目背景。 这是我的代码: 我只想添加图标背景,而不是所有项目背景。 这是我的代码: <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottom_navigation_main" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/surface_container_lowest" app:itemTextAppearanceActive="@style/Theme.FarmKeep.TextAppearance.SemiBold.LabelSmallProminent" app:itemTextAppearanceInactive="@style/Theme.FarmKeep.TextAppearance.Regular.LabelSmall" app:itemTextColor="@color/on_surface" app:labelVisibilityMode="labeled" app:itemBackground="@drawable/selector_bottom_nav_background app:menu="@menu/menu_main"/> 背景填充了图标和文字,那么我怎样才能像附图一样只填充图标呢? 谢谢! 图片中的菜单来自material3风格,因此您的应用程序主题或至少bottom_navigation_main主题必须具有来自Theme.Material3的父主题,例如Theme.Material3.DayNight.NoActionBar。这样它应该可以正常工作,只需删除 app:itemBackground="@drawable/selector_bottom_nav_background" 线即可。 如果您不想更改整个应用程序主题,请添加 android:theme="@style/Theme.Material3.DayNight" 仅为导航设置主题,它应该如下所示: <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottom_navigation_main" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/surface_container_lowest" app:itemTextAppearanceActive="@style/Theme.FarmKeep.TextAppearance.SemiBold.LabelSmallProminent" app:itemTextAppearanceInactive="@style/Theme.FarmKeep.TextAppearance.Regular.LabelSmall" app:itemTextColor="@color/on_surface" app:labelVisibilityMode="labeled" android:theme="@style/Theme.Material3.DayNight" app:menu="@menu/menu_main"/> 试试这个: <!-- res/drawable/icon_selector.xml --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true"> <layer-list> <item> <shape android:shape="oval"> <solid android:color="#FF6200EE"/> <!-- Background color for the selected state --> <size android:width="24dp" android:height="24dp"/> </shape> </item> <item android:drawable="@drawable/ic_your_icon" android:gravity="center"/> </layer-list> </item> <item android:drawable="@drawable/ic_your_icon"/> <!-- Default icon --> </selector> 其他布局: <!-- res/menu/menu_main.xml --> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/navigation_home" android:icon="@drawable/icon_selector" android:title="@string/title_home" /> <!-- Other items --> </menu>

回答 2 投票 0

仅为底部导航栏中的图标添加背景android

我只想添加图标背景而不是所有项目背景。 这是我的代码: 我只想添加图标背景,而不是所有项目背景。 这是我的代码: <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottom_navigation_main" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/surface_container_lowest" app:itemTextAppearanceActive="@style/Theme.FarmKeep.TextAppearance.SemiBold.LabelSmallProminent" app:itemTextAppearanceInactive="@style/Theme.FarmKeep.TextAppearance.Regular.LabelSmall" app:itemTextColor="@color/on_surface" app:labelVisibilityMode="labeled" app:itemBackground="@drawable/selector_bottom_nav_background" app:menu="@menu/menu_main"/> 背景填充了图标和文字,所以我怎样才能像附图一样只填充图标呢? 谢谢! 图片中的菜单来自material3风格,因此您的应用程序主题或至少bottom_navigation_main主题必须具有来自Theme.Material3的父主题,例如Theme.Material3.DayNight.NoActionBar。这样它应该可以正常工作,只需删除 app:itemBackground="@drawable/selector_bottom_nav_background" 线即可。 如果您不想更改整个应用程序主题,请添加 android:theme="@style/Theme.Material3.DayNight" 仅为导航设置主题,它应该如下所示: <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottom_navigation_main" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/surface_container_lowest" app:itemTextAppearanceActive="@style/Theme.FarmKeep.TextAppearance.SemiBold.LabelSmallProminent" app:itemTextAppearanceInactive="@style/Theme.FarmKeep.TextAppearance.Regular.LabelSmall" app:itemTextColor="@color/on_surface" app:labelVisibilityMode="labeled" android:theme="@style/Theme.Material3.DayNight" app:menu="@menu/menu_main"/> 试试这个: <!-- res/drawable/icon_selector.xml --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true"> <layer-list> <item> <shape android:shape="oval"> <solid android:color="#FF6200EE"/> <!-- Background color for the selected state --> <size android:width="24dp" android:height="24dp"/> </shape> </item> <item android:drawable="@drawable/ic_your_icon" android:gravity="center"/> </layer-list> </item> <item android:drawable="@drawable/ic_your_icon"/> <!-- Default icon --> </selector> <!-- res/menu/menu_main.xml --> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/navigation_home" android:icon="@drawable/icon_selector" android:title="@string/title_home" /> <!-- Other items --> </menu>

回答 2 投票 0

按下 BottomNavigationBar 项目总是会创建一个实例,并将旧的实例保留在 backstack 中

我正在为我的应用程序使用 Android 导航组件和 BottomNavigationBar。 实施 我有四个选项卡,并且为每个选项卡和 1 个导航创建了一个单独的导航图...

回答 1 投票 0

如何去掉底部导航栏内的小圆角矩形框?

我制作了一个底部导航栏,里面有一个小矩形框。我到处搜索但找不到解决方案。如果有的话,我什至多次使用代码

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.