I use this code in my menu.xml:
<item android:id="#+id/physics"
android:icon="#drawable/ic_action_***"
android:title="#string/physics"
android:orderInCategory="2"
android:showAsAction="always"/>
Now my Icons aren't very much saying about the button they stand for.
So I wan't display them AND the title.
After long google research I found this on #stackoverflow:
Android Menu Icon with Title : Title doesn't display
But it's about the icons. I downloaded my icons already in the right size and put them in the right folder.
And I don't have problems with my icons, they are showing great, but when you see a line chart, you don't automatically think of physics, do you?
Any idea, how to display both? I also added a sting, it doesn't show up (is it even possible?)
Any idea, how to display both?
Replace:
android:showAsAction="always"
with:
android:showAsAction="always|withText"
Related
I've currently been looking into the navigation drawer of android and see the example code from android they use.
When starting a new project and selecting the navigation drawer activity. It gives basic structure which is great.
From this I see the icons used in the navigation drawer are android default. I wanted to see if possible to add my own png for icons. So far my code (in activity_main_drawer) is
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_connect"
android:icon="#drawable/icon_menu_connect_24"
android:title="Connect" />
<item
android:id="#+id/nav_settings"
android:icon="#drawable/icon_menu_settings_24"
android:title="Settings" />
<item
android:id="#+id/nav_help"
android:icon="#drawable/icon_menu_help_24"
android:title="Help" />
</group>
the _24 at the end of the name is just the 24pixel size indication.
Now after running this code all i get appear in my navigation drawer is square blocks and not the image.
Reason for using own png rather than android default, is looking at the defaults there was no images indicating what i wanted.
Appollogies if question has been posted before and thanks in advance
I have found the issue. I found that the image used in the menus need to have a transparent background. The images I was using did not get saved in that format and thus showed as a grey block. So although it gave a preview in the left hand margin in the XML file, it still was not in the right format
Using image asset to generate the icons was more efficient than lots of .PNG files
First of all, sorry for my bad english, I'm trying my best for this question.
This is my problem:
I'm doing an app about drawing, and I'm trying to show icons on the drop down menu, instead of the title, but I am not able to show the icon.
I have tried this:
<item android:id="#+id/pickColor" android:title="#string/pickColor"
android:icon="#drawable/colors"
android:orderInCategory="100" app:showAsAction="always"
/>
and this shows me the icon in the ActionBar.
However if I change the parameter app:showAsAction="always"
to this app:showAsAction="never" the app shows the title from that menu item.
So my problem it's that I want to show a dropdown menu but only with icons instead of the default titles.
Thank you for your help.
Read this post:
http://android-er.blogspot.co.uk/2010/12/custom-arrayadapter-for-spinner-with.html
Or this tutorial:
http://android-developers.blogspot.in/2011/04/customizing-action-bar.html
I have tried setting the:
android:showAsAction=".."
to every one of these:
ifRoom, never, withText, always, collapseActionView
but I always got the same result, which is not having any buttons on the action bar, so I have to press the 'menu' button.
Here is a picture of the menu now :
<item android:id="#+id/smth1"
android:title="#string/smth1"
android:showAsAction="always"
android:orderInCategory="1" />
I have even tried adding this:
android:uiOptions="splitActionBarWhenNarrow"
into application manifest file, but with no positive result (nothing changed).
I have tried running it on various kind of APIs (14, 16, 17, 19), but with the same result.
If my question seems to be unclear, here is a picture of a menu, which I would like to have:
Thanks for any help.
You need to use the compatibility namespace (see here)
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/menu_add_size"
android:title="#string/menu_add_item"
android:icon="#android:drawable/ic_menu_add"
app:showAsAction="always"/>
</menu>
Once you're using that you can use as many menu buttons as will fit. You're no longer limited to just two buttons + overflow showing.
You maybe just don't have enough space, you should first remove the title from your Activity by adding this to your onCreate method:
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
Then you can see here that the maximum number of icons you can display is directly linked to the width of your screen, on small phones you will only be able to see 2 icons in the ActionBar.
I have the following setup:
So you can click on the search icon for the action bar to turn into a search bar. Pretty standard:
So if you're done searching you can click the Home icon to make the bar go away:
But when you go back, the navigation dropdown menu is shifted to the right quite a bit:
I can't really figure out what is happening here. The first thing I did was make a brand new app and recreate it (which is what you see below) to make sure it wasn't an issue with styles or themes I'm using in my main app. That didn't help the problem. I'm using ActionBarSherlock, so the next thing I did was rebuild the project using Google's official Action Bar API. That didn't make a difference either.
Does anyone have any ideas? I'll provide any code you guys think could help, but I took the implementation pretty much straight from Google's docs about it. Thanks!
EDIT: Adding some before-after images with layout borders visible (dev options feature in 4.1+)
BEFORE:
AFTER:
I've also included the menu XML:
<?xml version="1.0" encoding="utf-8"?>
<item android:id="#+id/abm_search"
android:icon="#android:drawable/ic_menu_search"
android:showAsAction="always|collapseActionView"
android:actionViewClass="android.widget.SearchView" />
<item android:id="#+id/abm_location"
android:title="Stuff"
android:showAsAction="never" />
<item android:id="#+id/abm_radius"
android:title="More Stuff"
android:showAsAction="never" />
<item android:id="#+id/abm_settings"
android:title="Other Stuff"
android:showAsAction="never"/>
Found out the problem. I had given the action bar a title of "". Instead, if you gave the action bar this display option:
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME);
it fixed the problem. Hope this helps someone else.
I'd like to have an app layout as the one they used for Gmail. They have the actionbar that has icons (on my device it has the app logo for up navigation, and a custom view for selecting priority inbox/inbox/etc), but there is also some kind of split ActionBar because at the bottom I have several icons (compose, search, labels, etc).
How could I do this? I have implemented the following ActionBar through this XML:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_gps"
android:icon="#drawable/icone_gps_continu"
android:showAsAction="always"
android:title="#string/menu_gps"/>
<item
android:id="#+id/menu_sort"
android:icon="#drawable/icone_liste_chron"
android:showAsAction="always"
android:title="#string/menu_liste"/>
<item
android:id="#+id/menu_stats"
android:icon="#drawable/icone_statistiques"
android:showAsAction="always"
android:title="#string/menu_stats"/>
<item
android:id="#+id/menu_save"
android:icon="#drawable/icone_terminersortie"
android:showAsAction="always"
android:title="#string/menu_save"/>
<item
android:id="#+id/menu_search"
android:icon="#drawable/ic_launcher"
android:showAsAction="always"
android:title="#string/menu_search"/>
<item
android:id="#+id/menu_photo"
android:icon="#drawable/icone_enregistrerphoto"
android:showAsAction="always"
android:title="#string/menu_photo">
</item>
<item
android:id="#+id/menu_sound"
android:icon="#drawable/icone_enregistrerson"
android:showAsAction="always"
android:title="#string/menu_sound">
</item>
<item
android:id="#+id/menu_settings"
android:icon="#drawable/icone_parametres"
android:showAsAction="always"
android:title="#string/menu_settings">
</item>
</menu>
And I have of course enabled the split ActionBar by adding android:uiOptions="splitActionBarWhenNarrow" to my <application> tag in the manifest.
What I get though is an empty "top" ActionBar; and the bottom one is displaying only three icons. I thought I could display like 3-4 icons at the top and 5 at the bottom in portait mode, and all of them at the top in landscape mode.
Note: even if I'm testing on ICS with my Galaxy Nexus, I'm using ActionBarSherlock in order to provide backward compatibility.
Looks like I posted too fast, it seems it's not possible.
Duplicates:
How to Place ActionBar Items in Main ActionBar and Bottom Bar
Android Split Action Bar with Action Items on the top and bottom?
Apparently this is not possible. However they did it in gmail/gplus, maybe using a custom view for the bottom part... Still expecting a better answer to this!
Reto Meier's word on this:
I think the problem with splitting the actions between the top and bottom is that it would make it more difficult to perform actions. Actions should be the most important things to do on an Activity -- splitting them between the top and bottom of the screen means users need to look in two places rather than one.
I was also wondering how these apps had icons in both bars, so I decompiled two of them.
What I found is that these two apps didn't implement the ActionBar at all and use custom layouts for both bars. I'm not sure if I can name these apps here, but they are well known apps with 10M+ downloads.
I strongly suggest to go the same way if you don't like the default ActionBar (which have very little room for customization) and create custom layouts instead (not necessary for both bars, it depends on your needs).
It's quite easy to reproduce the split action bar layout. Its height is always 48dp whatever the device is, so a simple LinearLayout or RelativeLayout with a fixed height and some transparent image buttons work very vell. In only 15 minutes you get a fully customizable split action bar.