【发布时间】:2016-05-26 09:06:22
【问题描述】:
当我尝试显示我的 SearchView 时遇到了一些问题。
我需要什么:
1.使SearchView始终打开而没有任何关闭按钮。
2.在Searchview
之后显示另一个图标我的代码:
menu_fragment_xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".CardBaseFragment">
<item android:id="@+id/action_search"
android:title="Search"
style="@style/SearchViewStyle"
app:showAsAction="ifRoom|collapseActionView"
app:actionViewClass="android.support.v7.widget.SearchView"
/>
<item android:id="@+id/сhange_country"
android:title="@string/add_new_card"
app:showAsAction="always"
android:actionBarWidgetTheme="@style/myStyle"
android:icon="@drawable/ic_change_country">
</item>
</menu>
风格:
<style name="SearchViewStyle" parent="Widget.AppCompat.SearchView">
<!-- Gets rid of the "underline" in the text -->
<item name="queryBackground">@null</item>
<!-- Gets rid of the search icon when the SearchView is expanded -->
<item name="searchHintIcon">@null</item>
<!-- The hint text that appears when the user has not typed anything -->
<item name="queryHint">Test</item>
</style>
现在,当程序启动时,一切正常,但我仍然有返回按钮。
当我将 SearchView app:showAsAction="ifRoom|collapseActionView" 更改为 "always" 时,SearchView 与我的第二项重叠,如何正确删除后退按钮,而不为工具栏创建新布局?
((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
没有帮助。
【问题讨论】:
-
为它创建您自己的自定义布局,如果您不想要它的任何功能,请不要使用 searchview。
-
@VivekMishra 我需要 searchview 功能,我需要它始终打开,我只想禁用 searchview 折叠
-
此问题在 Android 23 及更高版本上很常见 stackoverflow.com/questions/56410048/…
标签: android android-actionbar android-toolbar searchview android-appcompat