n388mm
n388mm

Reputation: 81

ActionBarSherlock Switch Toggle

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

Answers (3)

Josh
Josh

Reputation: 10738

You can add a custom view to the action bar's menu using an action view.

Upvotes: 1

Climbatize
Climbatize

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

chuckliddell0
chuckliddell0

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

Related Questions