Android: Full-Size SearchView in ActionBar

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

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

... I get an empty field on the left:

Search bar

+4
source share
1 answer

I solved this using the toolbar and setting the following options:

    <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 you can put a SearchView or use the toolbar items using menu.xml, which has a toolbar. See Android Developer Docs.

+2
source

All Articles