salezica
salezica

Reputation: 76909

Android: full-width SearchView in ActionBar

I want a SearchView to fully take up the full width of the ActionBar (support v7), but even after calling...

actionBar.setHomeButtonEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);

... I get a blank space to the left:

Search bar

Upvotes: 4

Views: 3261

Answers (1)

TjerkW
TjerkW

Reputation: 2150

I solved it by using a Toolbar and setting the following paramters:

    <android.support.v7.widget.Toolbar
        android:id="@+id/tbToolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:paddingLeft="0dp"
        android:background="?attr/colorPrimary"
        android:contentInsetLeft="0dp"
        android:contentInsetStart="0dp"
        app:contentInsetLeft="0dp"
        app:contentInsetStart="0dp"
        app:contentInsetStartWithNavigation="0dp">

Inside that you can put a SearchView or use your toolbar items with a menu.xml which has a toolbarview. See the android developer docs.

Upvotes: 2

Related Questions