Icon of about in actionbar doesn't appear in the MainActivity it appear in the overflow menu but in the others Activity it appears without any problems
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" >
<item
android:id="#+id/about_app"
android:icon="#drawable/ic_action_about"
android:showAsAction="ifRoom"
android:title="#string/about_app"/>
</menu>
But when I change it to this
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" >
<item
android:id="#+id/about_app"
android:icon="#drawable/ic_action_about"
app:showAsAction="ifRoom"
android:title="#string/about_app"/>
</menu>
The icon of about appear in just the MainActivity and in the others Activitys it diseapper and it appear in the overflow menu
If you are using the Android Support library you should use app:showAsAction="ifRoom" (Note the app: namespace).
To make an action bar item visible always change ifRoom to always, otherwise, if the title is long the system will place the item in the overflow menu.
The problem come from the MainActivity because I extends ActionBarActivity for App who have API 11, to resolve the problem you should extends Activity and use the android:showAsAction and for API 11 or higher than 11.
Related
My ActionBar has 2 action buttons, when I'm trying to change logo on my ActionBar, it doesn't show. I found the solution: in my Mainactivity class I changed ActionBarActivity(it shows by default) to Activity. Then in manifest.xml I change the Theme from
name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to
name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
the logo appeared, but 2 action buttons moved to overflow menu. The question is: How to move this action buttons back?
My menu_main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item android:id="#+id/action_share"
android:title="#string/action_share"
android:icon="#drawable/ic_action_share"
android:orderInCategory="110"
app:showAsAction="always" />
<item android:id="#+id/deleteNote"
android:title="#string/delete"
android:orderInCategory="111"
android:icon="#drawable/ic_action_delete"
app:showAsAction="always" />
</menu>
MainActivity
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
if (isAddingNote)
{
menu.removeItem(R.id.deleteNote);
menu.removeItem(R.id.action_share);
}
return true;
On this forum I found two close posts but it didn't help me.
Action buttons doesn't show up on Action Bar?
and Actionbar not shown with AppCompat
As per my understanding to your question you were originally trying to change the icon of the actionBar in which you didn't succeed and end up with other error.
Let me tell you that your menu_main.xml code works perfectly there is no error in that.
There are two possible solutions for you and that depends on your requirements.
If you are developing your app with material design support i.e using Appcompat then use following answer.
Change android:Theme.Holo.Light.DarkActionBar to Theme.AppCompat.Light.DarkActionBar again.
Change extends Activity to extends ActionBarActivity again.
Write this code in your java file to change the logo of the actionbar.
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
actionBar.setIcon(R.drawable.YourLogo);`
If you want to implement your app with Holo theme then use following answer.
First of all remove Appcompat lib from your project depending on the IDE you are using.
Let your activity be extends Activity.
Let your theme be android:Theme.Holo.Light.DarkActionBar.
Change TargetSDK to below 21. Change compile version to below 21.
Replace you main_menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/action_share"
android:title="share"
android:orderInCategory="110"
android:showAsAction="always"
android:icon="#drawable/ic_action_share" />
<item android:id="#+id/deleteNote"
android:title="delete"
android:orderInCategory="111"
android:showAsAction="always"
android:icon="#drawable/ic_action_delete" />
</menu>
P.S. I do not understand why you removing menu items from your code.
I.e.
if (isAddingNote)
{
menu.removeItem(R.id.deleteNote);
menu.removeItem(R.id.action_share);
}
in my android application i have a few Activities which extends ListActivity. What i want is to have a split ActionBar and or Icons in my ActionBar in those extended Activities.
Currently it doesent work. The Items in ListActivities are just shown in the onCreateOptionsMenu (three dots). I just created a simple layout for a test and modifided my manifest file.
Layout:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/new_game"
android:title="t1"
android:icon="#drawable/abc_ic_search"
app:showAsAction="ifRoom|withText"/>
<item android:id="#+id/help"
android:title="t2"
android:icon="#drawable/abc_ic_search"
app:showAsAction="ifRoom|withText" />
<item android:id="#+id/help2"
android:title="t2"
android:icon="#drawable/abc_ic_search"
app:showAsAction="ifRoom|withText" />
<item android:id="#+id/help3"
android:icon="#drawable/abc_ic_search"
android:title="t2"
app:showAsAction="ifRoom|withText" />
and in my manifest i tried to add the following to the application tag or just to the ListActivites.
<meta-data android:name="android.support.UI_OPTIONS"
android:value="splitActionBarWhenNarrow" />
In Activities which extend ActionBarActivity everything is running correct. Am i missing something for ListActivities? Does anyone have an idea?
help would be awesome! thanks
try to remove app:showAsAction="ifRoom|withText" or change it to app:showAsAction="always
take a look at this lik
ifRoom : Only place this item in the Action Bar if there is room for it.
withText : Also include the title text (defined by android:title) with the action item. You can include this value along with one of the others as a flag set, by separating them with a pipe |.
never : Never place this item in the Action Bar.
always : Always place this item in the Action Bar. Avoid using this unless it's critical that the item always appear in the action bar. Setting multiple items to always appear as action items can result in them overlapping with other UI in the action bar.
Okay i guess i figured out why it doesent show the splitactionbar. In addition to the meta tag you need to set the attribute uiOptions for a ListActivity + use the android namespace.
android:showAsAction="always"
android:uiOptions="splitActionBarWhenNarrow"
This option is only used for API Level 14 and higher. For Versions lesss than that ive no Idea so far to solve the problem.
A common pattern I see in many apps that provide some search functionality is to have the search widget clear the other menu icons off of the ActionBar. This works for me right now just by using ifRoom for showAsAction in my menu items. I'd like to show more menu items in the actionbar though, because it seems that the ActionBar is very conservative with how it determines ifRoom and consequently at least one important menu item is pushed to the overflow (perhaps someone smarter than me knows why they do that).
So how can I set showAsAction as always while still clearing the menu items off of the ActionBar when the Search Widget is activated? When I try that now, the menu items don't move, and the search widget is condensed.
Here's my menu:
<item
android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
android:showAsAction="collapseActionView|always"
android:actionViewClass="android.widget.SearchView" />
<item
android:id="#+id/action_stores"
android:title="#string/action_stores"
android:icon="#drawable/ic_action_stores"
android:showAsAction="always" />
<item
android:id="#+id/action_shopping_lists"
android:title="#string/action_shopping_lists"
android:icon="#drawable/ic_action_lists"
android:showAsAction="always" />
<item
android:id="#+id/action_preferences"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="never"/>
My searchable.xml
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="#string/app_name"
android:hint="#string/search_hint" >
</searchable>
Couldn't you set an onClickListener on the search widget that then runs some few lines of code to make the other MenuItems change from 'always' to 'ifRoom'?
The few lines of code within the onClickListener would contain something like this:
myMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
whereas myMenuItem is your MenuItem that should go from 'always' to 'ifRoom'.
You can change it back later in an appropriate method.
I have two menu items: Settings and Exit. When I run my code, with both set to showAsAction:"always", none of them show up on the screen when I press the menu button on my phone. This also happens if I set both to "ifRoom". However, if I set one to "never", the other one will show up. How can I get both items to show up? I am running a ~3.5 inch android 4.1.2 phone. I am using the android:theme="#style/Theme.AppCompat" theme.
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity" >
<group android:checkableBehavior="single">
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
app:showAsAction="ifRoom|withText"
android:icon="#drawable/sun"/>
<item android:id="#+id/exit_the_app"
android:title="#string/options_exit_text"
app:showAsAction="ifRoom|withText"
android:orderInCategory="101"
android:icon="#drawable/night"/>
</group>
</menu>
This is the screen when both items are set to "always" or "ifRoom", no menu items show up:
This is the screen when settings is set to "never", the exit item shows up:
There seems to be enough room, so how do I make both items show up? Thank you.
When showAsAction is set to ifRoom or always the item is shown in the action bar instead of the overflow menu (only if there's room in the case of ifRoom). This is the expected behavior.
If you want them to both show up in the overflow menu, set showAsAction to never for both.
I suggest reading the documentation: http://developer.android.com/guide/topics/ui/actionbar.html
I am backporting my app to API7 with AppCompat and have a problem with the actionbar.
When I use FragmentActivity the actionbar is shown on my phone (API18), but with ActionBarActivity it shows up as the optionmenu by pressing the menubutton.
On the emulator with API7 the actionbar is always shown as an optionsmenu.
Any ideas?
Use the compat name space for your menu items like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:compat="http://schemas.android.com/apk/res-auto" >
<item android:id="#+id/action_whatever"
android:icon="#drawable/ic_action_whatever"
android:title="#string/whatever"
compat:showAsAction="ifRoom" />
</menu>
Related to a duplicate that points to this post, I was having trouble making my buttons appear as action items instead of overflow items, despite having showAsAction set to always. I managed to coerce it by extending my activity with Activity instead of ActionBarActivity. According to this answer, this is acceptable if you don't need to support api levels below 11.
...extends ActionBarActivity:
...extends Activity:
I do debug with Doogee Valencia Y100Pro, and menu as "three little square" not visible, but when I extended my MainActivity with android.support.v7.app.ActionBarActivity, then I obtain text/icon menu in action bar. Next screenshot and menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_update"
android:icon="#drawable/ic_refresh"
android:title="#string/action_update"
app:showAsAction="always"/>
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
app:showAsAction="ifRoom"/>
</menu>