gpt4 book ai didi

android - SearchView:为什么不显示玻璃图标

转载 作者:行者123 更新时间:2023-11-29 23:23:55 29 4
gpt4 key购买 nike

Android Studio 3.2.1

在我的app / build.gradle中:

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.myproject"
minSdkVersion 18
targetSdkVersion 28
versionCode 1
versionName "1.1.1"


这是我的小部件:

import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SearchView;

private MenuItem searchMenuItem;

searchMenuItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem menuItem) {
if (BuildConfig.DEBUG)
Log.d(TAG, "onMenuItemActionExpand(), press_magnifying_glass");
isSearchWidgetExpanded = true;
mToolbar.setBackgroundColor(ContextCompat.getColor(activity, R.color.search_view_background));
// Expand (click to magnifying glass) and give focus to
// SearchView automatically
searchView.setFocusable(true);
searchView.setIconified(false);
searchView.requestFocusFromTouch();
searchView.setIconifiedByDefault(false);

menu.setGroupVisible(R.id.main_menu_group, false);
return true;
}

@Override
public boolean onMenuItemActionCollapse(MenuItem menuItem) {
if (BuildConfig.DEBUG)
Log.d(TAG, "onMenuItemActionCollapse(), press_home_searchView");
isSearchWidgetExpanded = false;
mToolbar.setBackgroundColor(activity.getResources().getColor(R.color.factura_background_color));
searchView.setQuery("", false);
menu.setGroupVisible(R.id.main_menu_group, true);
AndroidUtil.hideKeyboard((Activity) activity);
return true;
}
});


这里的菜单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="md.factura.app.cart.CartActivity">

<group android:id="@+id/main_menu_group">
<item
android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/search"
app:actionViewClass="android.widget.SearchView"
app:showAsAction="ifRoom|collapseActionView" />
<item
android:id="@+id/changeLanguage"
android:title="@string/change_language"
app:showAsAction="never" />
<item
android:id="@+id/report_or_review"
android:title="@string/report_issue"
app:showAsAction="never" />
<item
android:id="@+id/about"
android:title="@string/about"
app:showAsAction="never" />
<item
android:id="@+id/debug"
android:title="@string/debug_config"
android:visible="false"
app:showAsAction="never" />
</group>

</menu>


结果如下:


在单击玻璃图标之前:


enter image description here


单击玻璃图标后:


enter image description here


按下返回按钮后:
enter image description here


正如您在步骤#3之后看到的那样,图标玻璃不再显示。
为什么?

最佳答案

根据THIS,在菜单项中尝试替换:

app:showAsAction="ifRoom|collapseActionView"


与:

app:showAsAction="always|collapseActionView

关于android - SearchView:为什么不显示玻璃图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53836321/

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