Android: 在ActionBar中实现全宽度的SearchView

4

我希望SearchView在ActionBar(support v7)中能够占据整个宽度,但是即使调用了...

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

我左侧出现了一个空白:

搜索栏


访问此答案可能会对您有所帮助。 https://dev59.com/KmUo5IYBdhLWcg3wpg7N - Pragnesh Ghoda シ
你找到解决方案了吗? - JFouad
1个回答

2

我通过使用工具栏并设置以下参数来解决了这个问题:

    <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,或者使用具有ToolbarView的menu.xml中的工具栏项。请参阅Android开发人员文档。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接