In my app I want to create a searchview within an actionbar. I've used the following code.
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/autocomplete_search"
android:icon="#drawable/search_light"
android:title="#string/what_form_edit_text"
app:showAsAction="ifRoom|collapseActionView"
app:actionViewClass="android.support.v7.widget.SearchView" /></menu>
With this code a search icons shows up in my activity. After clicking this icon the search view expands and aligns on the left side of my actionbar (the title is gone).
Now I want to achieve this behaviour when automatically expanding the searchview. I tried to change the values of showAsAction into "always" instead of "ifRoom|collapseActionView", but it's not working. The searchview gets expanded, but is aligned on the right side of the actionbar. Is there any way I am missing to align the searchview on the left side (without implementing my own toolbar and place the searchview within?). Thanks for any help :)
Try to use
app:showAsAction="ifRoom"
It should fix your issue.
Related
enter image description here
How to i print text on bottom of Action bar logo
<item android:title="Customer Inquiry"
android:id="#+id/customer_inquiry"
app:showAsAction="always|withText"
android:icon="#drawable/customer_inqury"/>
i set text but its not visible...!
there is no such option for MenuItem, by design these items don't and shouldn't have any text. if you really need those labels you need to write own drawing class and use app:actionLayout or even whole custom Toolbar set for Activity with setSupportActionBar(..) in Activity
I'm trying to implement search interface in actionbar like in Google Play Video App (https://play.google.com/store/apps/details?id=com.google.android.videos).
I think it is SearchView widget but don't understand how do same customization: add up button inside it, set background, and expand the full width of actionbar
#Quiny898 create a nice lib, have a look:
https://github.com/Quinny898/PersistentSearch
Use a standalone Toolbar and set it with an elevation, then inflate your menu in it.
You can add this item to your menu:
<item android:id="#+id/menu_search"
android:title="#string/action_search"
android:icon="#drawable/abc_ic_search_api_mtrl_alpha"
pawesome:showAsAction="ifRoom|collapseActionView"
pawesome:actionViewClass="android.support.v7.widget.SearchView"/>
I'm using not bad library for this: https://github.com/MiguelCatalan/MaterialSearchView
I have a nearly full screen dialog fragment in my app, containing a toolbar on top. I want to style this toolbar like in the Material design guidelines:
Toolbar XML:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_height="#dimen/abc_action_bar_default_height_material"
android:layout_width="match_parent"
android:title="#string/new_folder"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:background="#color/primary_dark"/>
menu 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">
<item
android:id="#+id/action_done"
android:title="#string/action_save"
android:icon="#drawable/ic_done_white_48dp"
android:orderInCategory="100"
app:showAsAction="always|withText" />
</menu>
In my Dialog Fragment, code relevant to the toolbar:
private Toolbar.OnMenuItemClickListener mMenuItemListener = new Toolbar.OnMenuItemClickListener() {
#Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case android.R.id.home:
dismiss();
return true;
case R.id.action_done:
dismiss();
return true;
}
return false;
}
...
mToolbar.setNavigationIcon(R.drawable.ic_close_white_48dp);
mToolbar.inflateMenu(R.menu.menu_folder);
mToolbar.setOnMenuItemClickListener(mMenuItemListener);
My toolbar looks like this:
I have four problems:
The 'Save' text is not displayed next to the checkmark, even though there is ample room for it
The X icon is too large (maybe use the 36dip version?)
The X icon is not clickable
The toolbar does not display the title ('New Folder')
What am I doing wrong?
Note that my toolbar is not set as the action bar! It's just a toolbar in a fragment.
The 'Save' text is not displayed next to the checkmark, even though
there is ample room for it
This is not possible. You can show only text or only icon.
The X icon is too large (maybe use the 36dip version?)
You should use 24dp version.
The toolbar does not display the title ('New Folder')
Because you are in Fragment so you need to set title explicitly into Toolbar and from you code i don't see source code that doing this. You need to do it programatically (via xml it seems it's broken) and i prefer to you use support library.
The X icon is not clickable
You need to use OnNavigationClickListener and not OnMenuClickListener, your X icon is navigation icon not menu icon.
I don't think that you should but texts in the menu side (right of the toolbar). Looking at the guidelines, you can see that is not a good practice, and all the examples show menus only with icons
From the guidelines, I think you should use 24dp (http://www.google.com/design/spec/style/icons.html#icons-system-icons in the section 'Clearance')
Use
toolbar.setNavigationOnClickListener();
you need to set the title like
toolbar.setTitle("'New Folder")
I have just starting using an ActionBar, everything is well apart from the search box. I am now wanting to use a SearchView but have found it to be hard to customize, is there a way to use my existing EditText based layout in place of the expandable SearchView?
The top one is the new SearchView and the bottom is my old one which I would like to use, I am not worried about any extras like autocomplete.
I have looked on google for some time but cannot find any solution, my XML for the menu looks like so :
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/btnSearch"
android:title="Search"
android:icon="#drawable/ic_action_search"
android:showAsAction="always|collapseActionView"
android:actionViewClass="android.widget.SearchView"
android:queryHint="blah blah"/>
...
</menu>
I have found that I can get the bottom line to look similar to my old search box by using some ugly looking reflection code, however it still does not look right, the padding etc is all wrong. I don't want any reflection, I just want to use my old layout.
I found something that could solve your problem:
http://www.techrepublic.com/blog/software-engineer/pro-tip-customize-the-android-search-view-widget/#.
I wrote this class to help with SearchView customization:
https://gist.github.com/jaredrummler/c408c9d897fd92d5d116
You could do something like this after inflating the menu in onCreateOptionsMenu:
SearchViewStyle.on(menu, R.id.your_search_id)
.setSearchPlateDrawableId(R.drawable.your_edit_text);
Is there a way to position the title text for a menu item to the left of the icon rather than to the right in an ActionBar? So in:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/forward"
android:title="Begin"
android:icon="#drawable/ForwardArrow"
android:showAsAction="always"></item>
</menu>
It would appear "Begin ->" instead of "-> Begin"
While you can define things like android:actionButtonStyle in a theme and apply that to your activity, I am not aware that you can use that to turn around and affect the positioning of the image versus the text.
However, you can use android:actionLayout in your <item> element to replace the stock action button with something else of your own design. If you putter around the Android source and find where these action buttons come from, I suspect that you will find that they are styled Button objects using the compound drawable stuff to put an image alongside the text caption. Cloning that and switching the side for the image, then using that for your actionLayout, should work, at least in theory.