如何解决菜单抽屉内的接近开关按钮
所以我正在开发一个 android studio 项目。基本上我有一个菜单抽屉,其中包含一些项目,其中一个包含我通过 my_layout.xml 文件创建的 switchCompat:
<item
android:id="@+id/item"
android:title="my_item"
android:icon="@drawable/my_icon"
app:actionLayout="@layout/my_layout"
></item>
my_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/my_switch"
android:layout_width="fill_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
所以基本上我想操作这个按钮,我在我的抽屉里使用 NavController。 我试着写
SwitchCompat switch=myNavView.getMenu().findItem(R.id.my_switch);
my_switch.setonClickListener(new OnClickListener...
但应用程序崩溃如此明显,这不是正确的方法。 如果有人能帮助我,我会很高兴:)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。