android - 是否能够处理包含的 xml 内的按钮按下
问题描述
是否能够处理包含的 xml 内的按钮按下(没有片段):
应用插件:'kotlin-android-extensions'
活动.kt
leftBarButton.setOnClickListener {
Log.d(TAG,"unaccessible!")
}
活动.xml
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:fitsSystemWindows="true">
<include layout="@layout/navbar"
android:id="@+id/navBar"/>
</LinearLayout>
导航栏.xml
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
android:fitsSystemWindows="true"
android:layout_marginBottom="5pt"
android:gravity="bottom">
<Button
android:id="@+id/leftBarButton"
android:layout_width="37dp"
android:layout_height="30dp"
android:layout_marginStart="@dimen/borderrmargin"
android:background="@drawable/ic_home"
android:layout_weight="0.1"/>
<TextView
android:id="@+id/titleApp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/colorTitleText"
android:textAlignment="center"
android:text="@string/title"
android:textSize="20sp"
android:layout_weight="0.8"/>
<Button
android:id="@+id/rightBarButton"
android:layout_width="37dp"
android:layout_height="30dp"
android:layout_marginEnd="@dimen/borderrmargin"
android:background="@drawable/ic_home"
android:layout_weight="0.1"/>
</LinearLayout>
</RelativeLayout>
</merge>
onClickListener 不起作用
解决方案
嘿,在您在包含的 xml 中添加合并标签之前,包含不起作用,尝试将您包含的 xml 包装在合并标签中。
推荐阅读
- fpga - 如何将“lwIP 库”添加到 Eclipse XSDK Zynq 应用程序项目?
- linux - 当要求用户在 Bash 中输入三个文件名时如何显示最新文件
- javascript - 如何停止点击触发器并开始一个新的?
- python - 如何在 matplotlib 文本中结合颜色和数字打印格式?
- azure-devops - 作为 Azure DevOps 管道的一部分,如何将 XSD 上传到 Azure 集成帐户?
- python - 从图表中抓取数据
- css - 将资产图像路径作为动态内联样式背景图像 url (Nuxt.js)
- mongodb - 该字段必须是一个累加器对象
- c# - 正则表达式并排匹配 2 个数字或字符
- php - Laravel:无法使用 Postman 表单数据获取帖子数据