2
我想在我的主菜单的操作栏上打开一个开关。空的空间在那里,我可以点击它,但没有开关。什么是解决方案?menuitem - 开关不显示在ActionBar
提前致谢!
switch_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/switchView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<android.support.v7.widget.SwitchCompat
android:id="@+id/switchForActionBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""/>
activtiy_main_action.xml:这在你的菜单
<item
android:id="@+id/myswitch"
android:title=""
app:showAsAction="always"
android:actionLayout="@layout/switch_layout">
</item>
MainActivity.java
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuinf = getMenuInflater();
menuinf.inflate(R.menu.activity_main_action, menu);
//getMenuInflater().inflate(R.menu.mainmenu, menu);
return super.onCreateOptionsMenu(menu);
}
您的开关使用交换机出现了!非常感谢您的快速帮助 –
@johnnycigar不客气。不要忘了upvote并标记我的答案为接受 –
*我想尝试,但由于某种原因,我必须等待*完成 –