Android:ActionBar中的全宽SearchView

我希望SearchView完全占用ActionBar的全部宽度(支持v7),但即使在调用后…

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

……我左边有一个空格:

最佳答案 我通过使用工具栏并设置以下参数来解决它:

    <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">

在里面你可以放置一个SearchView或使用你的工具栏项目和一个带有工具栏视图的menu.xml.查看android开发人员文档.

点赞