android menu item doesn't show an image - android

I have this menu layout
<item
android:id="#+id/refresh"
android:icon="#drawable/refresh"
android:title="#string/refresh"/>
<item
android:icon="#drawable/sort_neutral"
android:title="Sort By Date">
<menu>
<item
android:id="#+id/sortNewToOld"
android:icon="#drawable/sort_up"
android:title="Newest To Oldest"/>
<item
android:id="#+id/sortOldToNew"
android:icon="#drawable/sort_down"
android:title="Oldest To Newest"/>
</menu>
</item>
the items "#+id/refresh" and "#drawable/sort_neutral" are shown correctly, but the two icons inside the "android:title="Sort By Date" are not shown, I just can see the title of them. any help would be appreciated.
note
I am using real mobile song ericsson 2.3.1

Your icon are probably too large for the menu. Make sure you are using a correct icon size.

Related

Android add buttons to ActionBar

I have a problem, in my app I need to add 2 buttons to the ActionBar, i change the menĂ¹ file in this way
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/navigation_drawer"
android:icon="#drawable/ic_drawer"
android:title="Drawer"
android:showAsAction="ifRoom" />
<item android:id="#+id/info"
android:icon="#drawable/ic_info_outline_white_24dp"
android:title="info"
android:showAsAction="ifRoom" />
</menu>
but my items are in the overflow button without the image , only the text , how can I do to take off from there and make images appear on ActionBar ? it would be possible to put one on the left and one to the right of the name of the app ?
You can use android:showAsAction="always" to make them always show on the ActionBar.

Android Sub-Menu Items Have Extra White Space To Right of Icon

I have an Android sub-menu, declared with this code:
<item
android:icon="#drawable/ic_menu_share"
android:showAsAction="ifRoom"
android:title="Share">
<menu>
<item
android:id="#+id/menuSortNewest"
android:icon="#drawable/ic_menu_share"/>
<item
android:id="#+id/menuSortRating"
android:icon="#drawable/ic_menu_share"/>
</menu>
</item>
The problem is that each item in the menu is an icon with a bunch of extra white space to the right of the icon. I just want the icon with no white space beside it. How do I achieve that?
Here is a screenshot of the application:
OP, As per the discussion in the comments, it's likely you'll need to create your own PopUpMenu to get the functionality you desire, please see:
http://stackoverflow.com/a/21329225/1067946
For info on doing it.

Overflow ActionBar actions not showing in Menu for Android 2.x

I'm using ActionBarSherlock to provide a unified UI for my Android 2.x and Android 4.x users. I have a menu with 6 items.
On a 2.x, 480px wide device with an hdpi screen, only 5 of the icons show. The device has a hardware Menu button, but when I tap it, nothing shows up. I expected it to popup and show the Action that wasn't able to fit.
I expect either the three-vertical-dots button to appear in the ActionBar to show a dropdown with the overflowed actions or I expect the physical Menu button to show the old style menu with the overflowed actions.
What am I missing or what am I doing wrong?
Here is my defined menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/add"
android:icon="#drawable/ic_menu_btn_add"
android:showAsAction="always"
android:title="Add"/>
<item
android:id="#+id/calculateNPV"
android:icon="#drawable/menu_icon_npv"
android:showAsAction="always"
android:title="NPV"/>
<item
android:id="#+id/calculateIRR"
android:icon="#drawable/menu_icon_irr"
android:showAsAction="always"
android:title="IRR/YR"/>
<item
android:id="#+id/send"
android:icon="#android:drawable/ic_menu_share"
android:showAsAction="always"
android:title="#string/share_pdf"/>
<item
android:id="#+id/graph"
android:icon="#drawable/ic_menu_gallery"
android:showAsAction="always"
android:title="#string/view_cashflow_diagram"/>
<item
android:id="#+id/deleteReorder"
android:icon="#drawable/ic_menu_clear_playlist"
android:showAsAction="always"
android:title="#string/delete_reorder_cashflows"/>
</menu>

How to get options from the options menu into title bar ActionBar Sherlock android

I am trying to get my options to show up in the Title Bar. I'm using ActionBarSherlock and I can figure out how to remove the title in the title bar, but would like to replace the text with 2 options from my options menu.
I'm using this code, EmpubLite as an example for my application, but I can't figure out how Mark (the commonsware guy) got the icons from his options menu in the title bar. My options show up at the bottom in the action bar and this is taking up unnecessary room on the screen. I've been looking through examples here, but can't seem to find out exactly how to get options in the title bar. I'm hoping Mark (or someone) can explain.
would like to replace the text with 2 options from my options menu
Um, unless that happens automatically by removing the title, I suspect that's not possible.
but I can't figure out how Mark (the commonsware guy) got the icons from his options menu in the title bar
Well, you see, that's covered in this delightful little book... :-)
More seriously, android:showAsAction controls whether items should be in the overflow area (never), should be in the action bar (ifRoom), or really really should be in the action bar (always). That being said, always is a hint, not a demand, and the OS may still put your action bar items in the overflow on smaller screen sizes.
You did not state which of the EmPubLite series you are experimenting with. Early on, the items are all set to never:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/help"
android:icon="#android:drawable/ic_menu_help"
android:showAsAction="never"
android:title="#string/help"/>
<item
android:id="#+id/about"
android:icon="#android:drawable/ic_menu_info_details"
android:showAsAction="never"
android:title="#string/about">
</item>
</menu>
By the end of the series, we have some that ideally go into the action bar:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/notes"
android:icon="#android:drawable/ic_menu_edit"
android:showAsAction="ifRoom|withText"
android:title="#string/notes">
</item>
<item
android:id="#+id/update"
android:icon="#android:drawable/ic_menu_save"
android:showAsAction="ifRoom|withText"
android:title="#string/download_update">
</item>
<item
android:id="#+id/settings"
android:icon="#android:drawable/ic_menu_preferences"
android:showAsAction="never"
android:title="#string/settings">
</item>
<item
android:id="#+id/help"
android:icon="#android:drawable/ic_menu_help"
android:showAsAction="never"
android:title="#string/help">
</item>
<item
android:id="#+id/about"
android:icon="#android:drawable/ic_menu_info_details"
android:showAsAction="never"
android:title="#string/about">
</item>
</menu>
My options show up at the bottom in the action bar and this is taking up unnecessary room on the screen.
You have android:uiOptions="splitActionBarWhenNarrow" set in your manifest somewhere, then.

Android - How to display a submenu with ActionBarCompat

I implemented ActionBarCompat to have an ActionBar across different OS versions.
It is hidden on smartphones, and displayed only on tablets.
I see that in this screenshot: http://developer.android.com/resources/samples/ActionBarCompat/index.html, the Share option menu displays the Logout option in a submenu, but when I compiled and run the sample code on a tablet, the Logout option was completely hidden and there wasn't any option to display it as a submenu
Then I tried to do something like this:
<item
android:icon="#android:drawable/ic_menu_delete"
android:orderInCategory="1"
android:showAsAction="always"
android:title="#string/menu_logout">
<menu>
<item
android:id="#+id/menu_logout"
android:title="#string/menu_logout"/>
</menu>
</item>
And it really looks how I want - on a tablet, on a smartphone however, it has an undesired effect - when clicking the Logout option menu, it displays another context menu, which is because of nested menus I believe.
Do you know guys, how can I display a submenu when using the Action Bar on a tablet, and display just a regular option menu on smartphone? Maybe ActionBarCompat requires some additional configuration?
I found a solution.
The solution consists of having 2 separate menu resources files, for tablets and for smartphones: menu_tablet.xml, menu_smartphone.
For tablets, I display a submenu:
<item
android:icon="#android:drawable/ic_menu_delete"
android:orderInCategory="1"
android:showAsAction="always"
android:title="#string/menu_logout">
<menu>
<item
android:id="#+id/menu_logout"
android:title="#string/menu_logout"/>
</menu>
</item>
For smartphones I display as a regular option menu:
<item
android:icon="#android:drawable/ic_menu_delete"
android:orderInCategory="1"
android:showAsAction="always"
android:id="#+id/menu_logout"
android:title="#string/menu_logout" />
And then in the code I inflate the appropriate menu resource like this:
if(isTablet()){
menuInflater.inflate(R.menu.menu_tablet, menu);
}else{
menuInflater.inflate(R.menu.menu_smartphone, menu);
}

Categories

Resources