【发布时间】:2016-05-31 04:21:43
【问题描述】:
我正在尝试在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,那么它在工具栏上显示得很好,但我不希望它在那里,我希望它出现在我按下时打开的溢出菜单上3个点。
我知道可以选择使用复选标记,但我遵循的设计需要切换。
谢谢。
【问题讨论】:
标签: android android-appcompat android-toolbar android-compatibility