Adding a button to the Action Bar in Android? -
for reason, cannot button appear on action bar. have defined in xml file in /res/menu, along inflating , listening action. icon present in /res/drawable-hdpi. , nothing of interest shows in logcat. :(
xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/logout" android:icon="@drawable/logout" android:title="logout" android:orderincategory="100" android:showasaction="always" /> </menu>
code in main activity:
public class mainactivity extends actionbaractivity { @override public boolean oncreateoptionsmenu(menu menu) { menuinflater inflater = getmenuinflater(); inflater.inflate(r.menu.main_activity_actions, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle presses on action bar items switch (item.getitemid()) { case r.id.logout: //logout code return true; default: return super.onoptionsitemselected(item); } } //rest of app }
i followed question initial problem, , didn't help. how add button in actionbar(android)?
try change:
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:yourapp="http://schemas.android.com/apk/res-auto" > <item android:id="@+id/logout" android:icon="@drawable/logout" android:title="logout" android:orderincategory="100" yourapp:showasaction="always" /> </menu>
Comments
Post a Comment