【发布时间】:2014-02-03 09:53:26
【问题描述】:
我需要在设置中添加主开/关(开关)作为子菜单。我使用了单独的布局 xml 并将其作为 android:actionLayout 添加到 menu.xml。但不是切换,而是显示一个空行。那里没有显示开关。这是我使用的代码。 main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/menu"
android:orderInCategory="1"
android:showAsAction="never"
android:title="Menu"
/>
<item
android:id="@+id/myswtich"
android:showAsAction="never"
android:actionLayout="@layout/switch_layout"/>
</menu>
switch_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<Switch
android:id="@+id/switchForActionBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</RelativeLayout>
如果我在 menu.xml 中更改为 android:showAsAction="always" ,则该开关将显示在操作栏中。但我想要的是在子菜单中显示它。我的代码有什么问题?
【问题讨论】:
标签: android android-layout submenu