我在Toolbarandroid.support.v7.widget.SwitchCompat
上添加了一个开关。这是我的代码:
SwitchCompat 布局文件toolbar_switch.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<android.support.v7.widget.SwitchCompat
android:id="@+id/toolbar_switch"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=""/>
</RelativeLayout>
menu_main.xml
<menu 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"
tools:context=".MainActivity">
<item
android:id="@+id/action_clipboard_switch"
android:title=""
app:actionLayout="@layout/toolbar_switch"
android:checkable="true"
android:enabled="true"
app:showAsAction="always"/>
这段代码只是向我展示了工具栏上的一个开关。但是当我点击开关时没有任何反应。我什至不切换。
我还向 onClickListener 添加了一个 Toast,但它不起作用。帮助!!!
编辑Switch 和 SwitchCompat 都不起作用!