SearchView in OptionsMenu not full width
I had a similar issue, that the search bar did not fill the whole width,( but I had no other icons).
I solved it by adding in item:
android:actionLayout="@layout/my_search_view"
and in layout/my_search_view.xml :
<?xml version="1.0" encoding="utf-8"?>
<SearchView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
SearchView doesn't expand full width
MenuItemCompat's SearchView has a property named maxWidth. The following does the trick:
searchView.setMaxWidth( Integer.MAX_VALUE );
SearchView in ActionBar not full width
put it in your code :
searchView.setMaxWidth(Integer.MAX_VALUE);
How can I remove the left space between back button and SearchView
By default, Toolbar
have 16dp inset after backbutton. So, include app:contentInsetStartWithNavigation="0dp"
in Toolbar
, it will remove that whitespace.
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
android:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
app:contentInsetStart="0dp">
How to set expanded ActionView's width in SupportActionBar to fill the available space
The "magic" takes place in Toolbar.expandItemActionView
. This method overrides the layout parameters of the expanded ActionView
and sets the width to wrap_content
. Now to one possible solution:
Toolbar.expandItemActionView
checks if the ActionView
implements CollapsibleActionView
interface and calls CollapsibleActionView.onActionViewExpanded
method if this is the case. This is your chance to fix the layout paramters and set the width to match_parent
. Derive a custom class from the SeekBar
and let it implement CollapsibleActionView
:
public class CollapsibleSeekBar extends AppCompatSeekBar implements CollapsibleActionView {
public CollapsibleSeekBar(Context context) {
super(context);
}
public CollapsibleSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CollapsibleSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public void onActionViewExpanded() {
ViewGroup.LayoutParams params = getLayoutParams();
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
setLayoutParams(params);
requestLayout();
}
@Override
public void onActionViewCollapsed() {
}
}
Use it in your menu item via app:actionViewClass
.
Also make sure to use the appropriate CollapsibleActionView
.
If you are using android.support.v4.widget.Toolbar
you also need android.support.v7.view.CollapsibleActionView
.
If you have an android.widget.Toolbar
use android.view.CollapsibleActionView
Related Topics
Android - Periodic Background Service - Advice
How to Have 1 Firebase Database for 2 Apps with Different Package Names
How to Draw Dashed Polyline with Android Google Map Sdk V2
Load Images from Disk Cache with Picasso If Offline
Android: Google Maps Location with Low Battery Usage
Android Can't Record Video with Front Facing Camera, Mediarecorder Start Failed: -19
Can Gradientcolor Be Used to Define a Gradient for a Fill or Stroke Entirely in Xml
How to Use the Speechrecognizer API Directly for Speech Input
Error Inflating Class Collapsingtoolbarlayout
Cardview Inside Recyclerview Has Extra Margins
Can't Handle Both Click and Touch Events Simultaneously
Using Webview Sethttpauthusernamepassword
Okhttp Library - Networkonmainthreadexception on Simple Post