Reputation: 81
I'm trying to put a master switch toggle on the action bar and I'm having zero luck.. Can anybody tell me what I'm doing wrong? Thank you.
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_item_action_provider_action_bar">
<Switch android:id="@+id/monitored_switch"
android:text="Monitored switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:showAsAction = "always" />
</item>
</menu>
and
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getSupportMenuInflater().inflate(R.menu.menu, menu);
return true;
}
I'm positive that the menu is being created and displayed because if I add other items they show. Just not the toggle.. And I'm testing on an AVD running 4.0.3 and my phone running 4.0.4
Upvotes: 2
Views: 2134
Reputation: 10738
You can add a custom view to the action bar's menu using an action view
.
Upvotes: 1
Reputation: 1123
By the way, why using ActionBar Sherlock if you use a switch? switch appeared with API 14, which doesn't need a compatibility framework :) (I'm just curious)
Upvotes: 0
Reputation: 2061
Try this..
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.menu, menu);
return(super.onCreateOptionsMenu(menu));
}
I don't know if this will change anything for you but it's worth a try :)
Upvotes: 0