zoukankan      html  css  js  c++  java
  • android searchview 简单使用

    设置样式 drawable    bg_search/xml
    android:background="@drawable/bg_search"
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
        <!--这里是Linearlayout布局的背景颜色-->
        <solid android:color="@color/white" />
        <!--这里是设置边框线的粗细和颜色-->
        <stroke
            android:width="2dp"
            android:color="@color/el_warning" />
    
        <padding
            android:bottom="1dp"
            android:left="1dp"
            android:right="1dp"
            android:top="1dp" />
        <!--角的话,里边有参数可以单独设置-->
        <corners android:radius="20dp" />
    
    </shape>
    下面的处理不显示 icon 和 下划线  这里使用的时android
    设置左侧的icon 这里设置为不显示左侧icon  api22 以下无效果
    android:searchIcon="@null"    
    
    下面这两项处理不显示下划线   api21 以下无效果
    android:queryBackground="@null"
    android:submitBackground="@null"

     androidx 使用以下方式

    app:searchIcon="@null"
    app:queryBackground="@null"
    app:submitBackground="@null"

     简单使用

    search_view.requestFocus()
            search_view.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
                override fun onQueryTextChange(newText: String?): Boolean {
                    Log.d(tag,"textChange=$newText")
                    return false
                }
    
                override fun onQueryTextSubmit(query: String?): Boolean {
                    Log.d(tag,"textSubmit=$query")
                    if(query.isNullOrBlank()){
                        Toast.makeText(this@CourseSearch,"请输入搜索条件",Toast.LENGTH_SHORT).show()
                        return false
                    }
    
                    if(query.length < 2 || query.length > 20){
                        Toast.makeText(this@CourseSearch,"搜索条件2-20位字符",Toast.LENGTH_SHORT).show()
                        return false
                    }
                    //查询处理代码
                    return false
                }
            })
  • 相关阅读:
    aws 计费查询
    关于网络抖动
    word2vec和onehot
    缺少了目标的教育是彻底的失败
    做事要风险控制
    SPS中计算值公式函数简介
    Moss + InfoPath 表单工作流开发要点
    【译】What is the NDK? (2)
    【译】What is the NDK? (1)
    【译】Android平台上的Flex开发(3) 在桌面和移动设备上测试
  • 原文地址:https://www.cnblogs.com/rchao/p/11550147.html
Copyright © 2011-2022 走看看