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
Related
I am trying to achieve a uniform action bar across my app. I am currently trying to add a search widget. My app displays the magnifying glass, another icon, and the overflow menu icon in its actionbar.
I haven't yet added any search functionality I am just trying to get the icon to display how I want it.
The problem I have is that on my launch page the magnifying glass is displayed, and if clicked the field for entering a search term appears.
If the user then goes to another activity the magnifying glass will still appear in the action bar but if clicked nothing will happen. The only difference is that other activities display the "Up" arrow to the left of the android logo in the action bar but I don't think this is the reason the search widget isn't working.
How can I fix this so the user can enter a search term from any page?
Below is my xml code:
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/search_title"
android:showAsAction="collapseActionView|always"
app:showAsAction="always"
android:actionViewClass="android.widget.SearchView" />
My onPrepareOptionsMenu(), onCreateOptionsMenu() and onOptionsItemSelected() are all identical in every activity and since they work for the main page I believe the problem lies within this xml file.
I would prefer if the search would display always rather than moving into the overflow menu.
Thanks for your time
Just found a solution, I am using the support library for compatibility so I needed to use:
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/search_title"
android:showAsAction="collapseActionView|always"
app:showAsAction="collapseActionView|always"
app:actionViewClass="android.widget.SearchView"
android:actionViewClass="android.widget.SearchView" />
(I needed to add app:actionViewClass). I used this explanation to help me
https://stackoverflow.com/a/22829368/3707803
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.
How do you manage Icons with ABS and Gingerbread? As you can see from the Screenshots, I have a menu item "Help", that sits in the action bar, when there's room for it. (when nothing is selected). The icon looks good so far. But when it moves into the options menu, I probably should use another icon for better visibility :)
How do you normally do that? Any ideas? This is my menu xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/new_button"
android:showAsAction="always"
android:title="new"
android:icon="#drawable/content_new_calendar"/>
<item
android:id="#+id/share_button"
android:visible="false"
android:showAsAction="ifRoom"
android:title="share"
android:icon="#drawable/social_share"/>
<item
android:id="#+id/help_button"
android:showAsAction="ifRoom"
android:title="help"
android:icon="#drawable/action_help"/>
</menu>
I know how to create different menus for various api levels, etc. But here, the same phone is showing the icon in the action bar and in the options menu. The simplest solution is to set android:showAsAction="never", but from user reviews I learned, that the App is difficult to understand (especially the Widget-Part), so I would love to have the help menu visible. Any ideas?
P.S. I know that the App is ugly and unfinished. It's work in progress and will be polished :)
Try using the force overflow option like so:
<item name="absForceOverflow">true</item>
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"
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.