Android设计支持库的一个功能是为所有开发人员和所有Android 2.1或更高版本的设备带来了许多重要的材料设计组件。导航抽屉使您的应用程序具有轻松的UX导航功能,尤其适用于初次使用者。 NavigationView为开发人员提供了更容易建立Navigation Drawer UI的框架。
我正在开发一个带有带有片段和导航图的导航组件的Android应用程序。 我的应用程序有一个带有菜单项的 BottomNavigationView,如“将目的地绑定到菜单项”中所述 ...
每次单击导航抽屉项目时,它都会关闭并且不会重定向到意图活动 /* MainActivity.java */ NavigationView 导航View = findViewById(R.id.
移动到材质3后,分隔线的颜色不同了。我想改变它。 主题.xml: <question vote="1"> <p>移动到材质3后,分隔线的颜色不同了。我想改变它。</p> <p><a href="https://i.stack.imgur.com/viTIp.png" target="_blank"><img src="https://cdn.txt58.com/i/AWkuc3RhY2suaW1ndXIuY29tL3ZpVElwLnBuZw==" alt=""/></a></p> <p><strong>主题.xml:</strong></p> <pre><code><style name="AppTheme" parent="Theme.Material3.DayNight.NoActionBar"> </code></pre> <p><strong>menu_navigation.xml:</strong></p> <pre><code><menu xmlns:android="http://schemas.android.com/apk/res/android"> <group android:id="@+id/nav_top" android:checkableBehavior="single"> <item android:id="@+id/nav_request" android:icon="@drawable/icon_settings" android:title="HELLO" /> </group> <group android:id="@+id/nav_other" android:checkableBehavior="single"> <item android:id="@+id/nav_cancel_payment" android:icon="@drawable/icon_cancel" android:title="LOL" android:enabled="true"/> </group> </menu> </code></pre> <p>我的主要活动:</p> <pre><code><androidx.drawerlayout.widget.DrawerLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white" android:id="@+id/drawer"> <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="match_parent"> <com.google.android.material.navigation.NavigationView android:id="@+id/navigation" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" app:drawerLayoutCornerSize="0dp" app:dividerInsetStart="0dp" app:dividerInsetEnd="0dp" app:menu="@menu/menu_navigation" app:layout_constraintStart_toStartOf="parent" android:background="@android:color/white" app:headerLayout="@layout/nav_header_view"> </com.google.android.material.navigation.NavigationView> </androidx.drawerlayout.widget.DrawerLayout> </code></pre> <p>如何更改颜色?</p> </question> <answer tick="false" vote="1"> <p><pre>M3</pre>中的<strong><code>listDivider</code></strong>颜色基于应用程序主题中定义的<strong><pre><code>colorOutline</code></pre></strong>。</p> <p>在您的应用程序主题中更改它:</p> <pre><code><style name="App.Theme" parent="Theme.Material3.DayNight"> <!-- ...... --> <item name="colorOutline">@color/red500_dark</item> </style> </code></pre> <p>或者如果您只想覆盖布局中的 <pre><code>NavigationView</code></pre>,您可以使用:</p> <pre><code><com.google.android.material.navigation.NavigationView android:id="@+id/nav_view" android:theme="@style/ThemeOverlay.App.NavigationView" </code></pre> <p>与:</p> <pre><code><style name="ThemeOverlay.App.NavigationView" parent=""> <item name="colorOutline">@color/red500_dark</item> </style> </code></pre> <p><a href="https://i.stack.imgur.com/0NnV5.png" target="_blank"><img src="https://cdn.txt58.com/i/AWkuc3RhY2suaW1ndXIuY29tLzBOblY1LnBuZw==" alt=""/></a></p> </answer> <answer tick="false" vote="0"> <p>更新 AppTheme 中的 <strong>android:listDivider</strong>。如果您只想在 NavigationView 布局中更改它,您可以尝试此操作。</p> <pre><code><style name="Theme.NavigationView" parent="Widget.Material3.NavigationView"> <item name="materialThemeOverlay">@style/ThemeOverlay.NavigationView</item> </style> <style name="ThemeOverlay.Keepass.NavigationView" parent=""> <item name="android:listDivider">@color/green</item> </style> </code></pre> <p>现在您可以将其应用到您的 <strong>NavigationView</strong></p> <pre><code><com.google.android.material.navigation.NavigationView android:id="@+id/navigation" style="@style/Theme.NavigationView" android:layout_width="wrap_content" android:layout_height="match_parent" app:menu="@menu/menu_navigation" app:headerLayout="@layout/nav_header_view"> </code></pre> </answer> </body></html>
Android BottomNavigation startDestination 循环 onCreate 函数
我有一个非常简单的应用程序,其中包含一个包含 FragmentContainerView 和 BottomNavigationView 的 MainActivity。 在 FragmentContainerView 中,我想显示三个片段之一。仅碎片...
迁移到 AndroidX 后,膨胀类 com.google.android.material.navigation.NavigationView 时出错
将项目更新到 AndroidX 并将 targetSdkVersion 设置为 28 后,从商店安装它进行 Beta 测试时,我的项目崩溃了。 以下是我收到的错误日志: 2019-07-08 0...
如何在 Android Jetpack Compose 子屏幕的 TopAppBar 中设置标题和按钮
我有一个使用顶部应用栏和底部导航的应用程序。 每个底部选项卡都有自己的 NavHostController 导航。 在我的主页选项卡上,我有一个像这样的 NavHostController 有趣的 HomeNavHost...
如何从导航视图标题中获取图像 ID? (Kotlin、Android Studio)
我才开始学习 Kotlin,也许对于高级开发人员来说这会容易一些。我在导航视图上有标题,这个标题有图像,图像有 id。我想当我点击这张图片时,打开新的
如何根据指定条件以编程方式设置 MenuItem 的背景颜色?
我正在研究使用 NavigationView 和菜单资源的导航栏。我想根据其 id 是否与字符串匹配来更改 MenuItem 的背景颜色。 我试过使用 setActionVie ...
我想改变导航抽屉中Title1的颜色。
我在这里写的是一个问题,这个问题是我们从AppCompat库迁移到AndroidX库时引入的。在这样做的时候,我们从android.support.design.widget.NavigationView......转换到了AndroidX库。
我想更改图标的大小,但我不知道如何。我看到过人们在修复这些问题的帖子,但我不理解。您能帮我提供我的代码吗?
我将导航抽屉与来自Google的arcore sdk的AR-Fragment结合使用时遇到问题,这是一个屏幕截图:当我更改当前片段时,它可以按预期工作。 ...
Android导航抽屉的最大项目数是多少?] >> [[
我有一个Navigationview,可以通过编程添加项目,一切正常。唯一的问题是项目在关闭活动后消失。菜单菜单= navigationView.getMenu(); ...
我在XML代码中具有如下所示的NavigationView:android:id =“ @ + id / activityMainNavigationView” android:layout_width =“ wrap_content” android:layout_height =“ match_parent”应用:...
Android NavigationView setBackgroundTintList不起作用
我想在NavigationDrawer中设置所选项目的颜色和背景。它适用于文本和图标,但不适用于所选项目的背景。 ColorStateList textColors = new ...
我在Logcat中出现此错误:java.lang.NullPointerException:尝试在空对象上调用虚拟方法'android.view.Menu com.google.android.material.navigation.NavigationView.getMenu()...
将适配器设置为ExpendableListView类型不匹配
[当我尝试将适配器设置为ExpendableListView时,它期望使用ListAdapter,但是我想使用扩展BaseExpandableListAdapter的自定义ExpandableListAdapter,这是我的ExpandableListView ...
Android:导航组件不能同时使用: 和NavigationItemSelectedListener
我做了什么:我创建了Navigation Drawer Activity,作为Navigation Drawer Activity的更新新格式,根据新的Android体系结构,我使用了Navigation Component结构。 ...
((Android)onNavigationItemSelected方法未被调用
我正在为包含抽屉的Engineering Design项目开发Android应用。我的一组成员选择使用android.support.design.widget.NavigationView API来执行此操作,这是...