gpt4 book ai didi

android - 搜索 View 未显示在工具栏中

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:49:08 24 4
gpt4 key购买 nike

实际上,我在 Support AppCompat v7 lib 24.0.0 上的 Searchview 有问题。

SearchView 没有显示没有文本和输入文本(看截图)

enter image description here

搜索查询工作完美。

那是我的菜单

<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=".MainActivity">
<item
android:title="@string/search"
android:id="@+id/action_search"
android:icon="@drawable/ic_search_24dp"
app:showAsAction="ifRoom|collapseActionView"
app:actionViewClass="android.support.v7.widget.SearchView"/>
</menu>

这是我的 onCreateOptionsMenu;

menu.clear();
inflater.inflate(R.menu.menu_search, menu);
MenuItem searchItem = menu.findItem(R.id.action_search);
searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
//Perform the final search

return false;
}

@Override
public boolean onQueryTextChange(String newText) {
//Text has changed, apply filtering?

return false;
}
});

我希望有人能帮助我。 :)

塞巴斯蒂安

最佳答案

我也有这个问题,我已经将工具栏高度更改为绝对值而不是 wrap_content 并且问题解决了。我不知道为什么,但我认为这个问题与 CoordinatorLayout 和工具栏的高度有关,有些东西打破了 SearchView 的高度。如果我使用 LinearLayout 而不是 CoordinatorLayout 和 AppBarLayout,它就可以工作。

菜单.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_search"
android:icon="@drawable/ic_search_white_24dp"
android:orderInCategory="100"
android:title="@string/action_search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="always|collapseActionView" />
</menu>

布局.xml

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:paddingTop="@dimen/toolbar_top_padding"
android:background="?attr/colorPrimary"
app:title="@string/drawer_item_publisher_customization"
app:layout_scrollFlags="scroll|enterAlways|snap"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
app:tabGravity="fill"
style="@style/DefaultTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>

toolbar_height 值:

<dimen name="toolbar_height">75dp</dimen>

绝对高度值前(layout_height:"wrap_content"):
Before absolute height value

绝对高度值后(layout_height:"75dp"):
After absolute height value

关于android - 搜索 View 未显示在工具栏中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38038561/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com