我正在尝试在android.support.v7.widget.Toolbar
的溢出菜单中使用SwitchCompat
小部件,但我无法让它正常工作,它总是空白的。
这是我的菜单定义:
<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="com.oveflowtest.ScrollingActivity">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never"/>
<item android:id="@+id/test"
app:actionLayout="@layout/testlayout"
app:showAsAction="never"/>
</menu>
这里是 testlayout
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.SwitchCompat
android:layout_width="match_parent"
android:layout_height="match_parent" android:text="test"/>
</LinearLayout>
如果我将showAsAction
更改为always
而不是never
,则它会在工具栏上显示,但我不想要它在那里,我想要它出现在当我点击三个点时打开的溢出菜单中。
我知道有一个选项可以使用复选标记,但我正在遵循的设计需要使用开关。
谢谢。