首页 > 解决方案 > Android 搜索视图删除十字图标

问题描述

我根据我的设计使用自定义工具栏中的搜索视图,我有另一个十字图标,所以我想删除十字图标以在默认情况下由 android 提供的搜索视图。

<SearchView
    android:id="@+id/search_learning_fragment"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:queryHint="@string/toolBar_hint"
    android:clickable="true"
    android:searchIcon="@null"
    android:paddingTop="@dimen/element_padding_small"
    android:focusable="false"
    android:paddingBottom="@dimen/element_padding_small"
    android:background="@color/White"
    android:queryBackground="@color/White"
    android:iconifiedByDefault="false"
    android:layout_alignParentTop="true">
</SearchView>

ImageView searchViewIcon = (ImageView)searchView.findViewById(R.id.search_close_btn);
                        searchViewIcon.setVisibility(View.GONE);
                        Toast.makeText(CustomSearchActivity.this, ""+searchViewIcon, Toast.LENGTH_SHORT).show();

标签: android

解决方案


使用它来做到这一点-

searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String query) {
            ImageView searchViewIcon = (ImageView)searchView.findViewById(android.support.v7.appcompat.R.id.search_close_btn);
            searchViewIcon.setVisibility(View.GONE);
            return true;
        }
   });

推荐阅读