In the Gmail app, the search bar moves all the way to the left when you click on the search icon. Does anyone know how to recreate this effect? The current way I have it, the icon expands when clicked, but doesn't move to the left like the Gmail app. Here is my menu xml file:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu_search"
android:title="Search"
android:icon="#drawable/ic_menu_search"
android:showAsAction="ifRoom"
android:actionViewClass="android.widget.SearchView"
/>
</menu>
Take a look at this SO Question and see if that is what you're referring to:
Contextual Action Bar in Honeycomb
and
Contextual Action Bar in Honeycomb
The Gmail app seems to simply have a search icon in the menu and when you click on this it will add SearchView as the current navigation view with getActionBar.setCustomView().
There are a few gotchas when doing this, for example handling when it should be removed etc but if handled well it can lead to a nice user experience. But it may not be worth the hassle though, the regular expandable SearchView should be sufficient for most applications.
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
Not sure if this is the appropriate place for this question, but here goes. I'm following the android tutorial for creating apps and I'm finding some issues with the implementation of the menus in the action bar. (http://developer.android.com/training/basics/actionbar/setting-up.html). I am testing on my Samsung Galaxy S4.
I am making an App for Android 3.0 and above but when I follow those instructions, the menu doesn't appear in the action bar, but becomes visible only when I press the menu button. If I follow the Android 2.1 and above instructions, the menu buttons appear in the action bar, except the overflow menu which is activated by pressing the menu button.
What do I need to do for Android 3.0 and above to make the menu appear in the action bar? Or is this no longer the way it works and it is meant to appear using the menu button instead now?
In menu.xml use showAsAction="always"
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_start"
android:showAsAction="always"
android:title="Start"/>
<item
android:id="#+id/action_signout"
android:showAsAction="always"
android:title="logout"/>
</menu>
I am developing an application of my own and was reading this: http://developer.android.com/guide/topics/ui/menus.html
It says:
Beginning with Android 3.0, the Menu button is deprecated (some
devices don't have one), so you should migrate toward using the action
bar to provide access to actions and other options.
My app is only targeting android 4.2+. Does that mean I should present the menu options as only action bar icons ? What if there is not enough room available ?
Items that do not fit in the action bar will automatically be relegated to the overflow menu. All you have to do is set the android:showAsAction="ifRoom" property in your xml for the menu item.
This basically tells the system that this menu item should be displayed as an action icon if there is room available. If not, it should be shown as an overflow menu item.
It means that there is no more hardware Menu Button. Your menu items will be showed in popup under "three-doted icon". In menu.xml you can configure everything:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="#+id/action_example"
android:title="#string/action_example"
android:showAsAction="ifRoom" /> <!-- attention -->
<item
android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
android:showAsAction="never" />
</menu>
Read more here
If you need a lot of icons to be showed you can split ActionBar(second(bottom) menu bar will appear).
documantation of splitting
I hope mine explanation will be good enough:)
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 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.