SearchView的学习笔记

资料来源

searView属性及用法

    https://blog.csdn.net/fan7983377/article/details/52174866

    https://blog.csdn.net/airsaid/article/details/51087226

    android:focusable和android:focusableInTouchMode的区别

        https://blog.csdn.net/csdn_susan/article/details/46651557

带圆角的searchView的实现

    https://blog.csdn.net/yuanguixi/article/details/60871598

    https://blog.csdn.net/csdnzouqi/article/details/53508233

自定义搜索栏

    http://www.sohu.com/a/168613010_468731

一简介

SearchView是Android原生的搜索框控件,它提供了一个用户界面,用于用户搜索查询。 

SearchView默认是展示一个search的icon,点击icon展开搜索框,如果你想让搜索框默认就展开,可以通过setIconifiedByDefault(false);实现。

二属性

 

三监听事件

SearchView的监听器

//Sets a listener to inform when the focus of the query text field changes.查询字段改变焦点时触发
svSearchCustom.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                
            }
        });
//监听搜索栏内的动作
//submit 用户按下提交按钮的时候,触发,重写需要返回true才有效
//change 当搜索栏内字段改变的时候触发,重写返回true生效
svSearchCustom.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                return false;
            }
        });

 

 

 

 

 

 

 

填坑

1 Couldn't resolve resource @id/search_edit_frame

https://blog.csdn.net/likai_rabbit/article/details/56831195

解决方法

a用安卓自带的serchView替换V7包的searView

b,在searchView的父控件中添加属性

android:id="@+id/search_edit_frame"

 

2更改默认的搜索图标和文字颜色

Android SearchView 自定义SearchIcon和字体颜色大小

在21版本后,直接在layout文件中,更改searchIcon属性,可以更改搜索图标

更改默认的文字属性

//获取到TextView的ID
int id = mSearch.getContext().getResources().getIdentifier("android:id/search_src_text",null,null);
//获取到TextView的控件
TextView textView = (TextView) mSearch.findViewById(id);
//设置字体大小为14sp
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);//14sp
//设置字体颜色
textView.setTextColor(getActivity().getResources().getColor(R.color.search_txt_color)); 
//设置提示文字颜色
textView.setHintTextColor(getActivity().getResources().getColor(R.color.search_hint_color));
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值