Kotlin Drawer activity onclick 事件监听器
Kotlin Drawer activity onclick event listner
我在 Kotlin 中使用默认的导航抽屉 Activity 开始了一个新的 android 项目
最低 SDK api 28
我的 IDE 是 android studio 4.0.1
然后我运行在我的手机上进行测试。应用程序编译成功
但我认为缺少点击事件监听器。
切换菜单工作正常,但是一旦点击视图永远不会改变,并且找不到在不同菜单之间切换的方法 intent/fragments
我发现关于使用 onNavigationItemSelected
的导航抽屉有很多不同 post,但 none 使用最新版本。
我已经尝试实施 onOptionsItemSelected
,但找不到明确的文档
因此,如果您能帮助我,我将不胜感激:)
...抱歉我的英语不好
Url 回购 github => https://github.com/TVart/NavDrawerActivity
项目模板中存在排序问题。在 activity_main.xml
文件中,更改
<com.google.android.material.navigation.NavigationView
... />
<include
layout="@layout/app_bar_main"
... />
到
<include
layout="@layout/app_bar_main"
... />
<com.google.android.material.navigation.NavigationView
... />
示例应用在此之后应该可以运行。至于为什么顺序很重要,请查看 DrawerLayout
的官方文档:https://developer.android.com/reference/android/support/v4/widget/DrawerLayout
这是重要的部分:
To use a DrawerLayout, position your primary content view as the
first child with width and height of match_parent and no
layout_gravity>. Add drawers as child views after the main content
view and set the layout_gravity appropriately. Drawers commonly use
match_parent for height with a fixed width.
我在 Kotlin 中使用默认的导航抽屉 Activity 开始了一个新的 android 项目 最低 SDK api 28
我的 IDE 是 android studio 4.0.1
然后我运行在我的手机上进行测试。应用程序编译成功 但我认为缺少点击事件监听器。 切换菜单工作正常,但是一旦点击视图永远不会改变,并且找不到在不同菜单之间切换的方法 intent/fragments
我发现关于使用 onNavigationItemSelected
的导航抽屉有很多不同 post,但 none 使用最新版本。
我已经尝试实施 onOptionsItemSelected
,但找不到明确的文档
因此,如果您能帮助我,我将不胜感激:)
...抱歉我的英语不好
项目模板中存在排序问题。在 activity_main.xml
文件中,更改
<com.google.android.material.navigation.NavigationView
... />
<include
layout="@layout/app_bar_main"
... />
到
<include
layout="@layout/app_bar_main"
... />
<com.google.android.material.navigation.NavigationView
... />
示例应用在此之后应该可以运行。至于为什么顺序很重要,请查看 DrawerLayout
的官方文档:https://developer.android.com/reference/android/support/v4/widget/DrawerLayout
这是重要的部分:
To use a DrawerLayout, position your primary content view as the first child with width and height of match_parent and no layout_gravity>. Add drawers as child views after the main content view and set the layout_gravity appropriately. Drawers commonly use match_parent for height with a fixed width.