java - 如何使我的抽屉布局中包含的按钮可点击?
问题描述
我想单击抽屉布局中包含的按钮。我该怎么做?
这是xml文件
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".main.views.MainActivity"
tools:openDrawer="start">
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/activity_home"></include>
<androidx.appcompat.widget.Toolbar
android:id="@+id/ts_toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"></androidx.appcompat.widget.Toolbar>
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/drawer_header"
app:itemIconSize="35dp"
app:itemTextAppearance="@style/TextAppearance.AppCompat.Medium.Inverse"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/nav_menu"></com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
解决方案
val navView = findViewbyId(R.id.nav_View)
navView.setNavigationItemSelectedListener { item ->
when(item.itemId) {
R.id.YOUR_ID -> {
//click
}
}
true
}
推荐阅读
- google-home - 谷歌主页布局控制工作但没有语音命令
- javascript - 无法从 nodejs 连接到 SQL 数据库
- python - Python map() 函数 - ValueError:无法将字符串转换为浮点数
- javascript - 如何从数组中生成随机数量的项目
- python - Python递归将元组列表排序为树结构
- python-3.x - 找到的解决方案:执行代码时出现此错误 --> TypeError: not enough arguments for format string
- c# - Visual Studio 2015 输出异常
- c# - 用于带有 gridcell 的 vb.net 应用程序的 Selenium sendkeys
- laravel - Axios 在 Laravel 中重复前缀路由
- python - OpenCV-python 不导入