Tag: drawerlayout

为什么使用DrawerLayout给IllegalArgumentException:DrawerLayout必须用MeasureSpec.EXACTLY

以下是我的xml: <?xml version="1.0" encoding="utf-8"?> <layout> <android.support.v4.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/root_drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="tailamade.boop.CustomerHomeActivity" tools:openDrawer="start"> <include layout="@layout/content_customer_home" android:layout_width="match_parent" android:layout_height="match_parent" /> <android.support.design.widget.NavigationView android:id="@+id/navigationView" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" app:headerLayout="@layout/activity_main" app:menu="@menu/menu_customer_home" /> </android.support.v4.widget.DrawerLayout> </layout> 我也尝试编写我自己的CustomDrawerLayout像这样(没有运气): class CustomDrawerLayout : DrawerLayout { constructor(context: Context) : super(context) constructor(context: Context, attrs: AttributeSet) : super(context, attrs) constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, […]

Android NavigationView Headerlayout的视图元素不会触发点击事件

我正在尝试创建类似gmail的导航视图。 在标题布局中,我有一个图像视图和两个textView。 我已经注册了TextView的点击事件。 但是,当我点击onClick方法的侦听器不触发(代码是在Kotlin) navigation_view是我的NavigationView的ID var headerView = navigation_view.getHeaderView(0) var accountName: TextView = headerView.findViewById(R.id.account_name) accountName.setOnClickListener { Toast.makeText(this, "Redirect to login", Toast.LENGTH_LONG).show() } 当我点击textView和drawerLayout关闭时,从不显示toast。