GithubHelp home page GithubHelp logo

cardsearchview's Introduction

CardSearchView

本项目是受BilibiliSearchView的启发,因此想对其进行完善,打包成库,方便自己以后的使用,也方便大家的快速导入。 在此,感谢原作者

预览

获取

先在 build.gradle 的 repositories 添加:

allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

再在dependencies添加:

dependencies {
	        compile 'com.github.limuyang2:CardSearchView:1.0.3'
	}

使用

在根布局中添加以下代码:

xmlns:SearchView="http://schemas.android.com/apk/res-auto"

在布局中使用:

    <km.lmy.searchview.SearchView
        android:id="@+id/searchView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        SearchView:defaultState="open"
        SearchView:hintText="input name" />

xml设置属性说明

xml属性 类型 说明
SearchView:hintText String 输入框提示文本
SearchView:backIcon Drawable 返回按钮图标
SearchView:oneKeyCleanIcon Drawable 一键清除图标
SearchView:historyIcon Drawable 历史纪录左侧图标
SearchView:defaultState enum 控件初始状态是否处于打开状态(默认“close”),值:“open”、“close”
SearchView:historyTextColor Color Int 历史纪录文字颜色

Java方法设置属性说明

属性方法 传入数据类型 说明
setHintText String 输入框提示文本
setBackIcon int 返回按钮图标
setOneKeyCleanIcon int 一键清除图标
setHistoryIcon int 历史纪录左侧图标
defaultState int 控件初始状态是否处于打开状态(默认关闭) SearchView.CLOSE:关闭;SearchView.OPEN:打开
setHistoryTextColor int 历史纪录文字颜色
open 打开SearchView
close 关闭SearchView
autoOpenOrClose 自动打开关闭SearchView
isOpen 搜索框是否打开

Java方法使用说明

使用方法 传入数据类型 说明
addOneHistory String 添加一条历史纪录
addHistoryList List 添加历史纪录列表
setNewHistoryList List 设置全新的历史记录列表
setHistoryItemClickListener OnHistoryItemClickListener 设置历史纪录点击事件
setOnSearchActionListener OnSearchActionListener 设置软键盘搜索按钮点击事件
setOnInputTextChangeListener OnInputTextChangeListener 设置输入文本监听事件

示例参考

MainActivity.java

与ToolBar一起使用不显示?

原因

如下布局所示,当在Toolbar外嵌套AppBarLayout后,会有好看的阴影效果,这是在Android5.0后新加入的Material Design效果,强调布局的层级性。由于AppBarLayout会提高布局的Z轴坐标,产生层级,因此,在ToolBar上的其他控件会因为层级低于AppBarLayout而导致被遮盖。

<android.support.design.widget.AppBarLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:fitsSystemWindows="true">

    <android.support.v7.widget.Toolbar
        android:id="@+id/activity_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:titleTextColor="@android:color/white">

    </android.support.v7.widget.Toolbar>

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

解决办法如下

只需要将SearchView的层级提高到和AppBarLayout一样即可。在SearchView的XML中加入下面一句话即可。

android:elevation="5dp"

示例

<android.support.design.widget.AppBarLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:fitsSystemWindows="true">

    <android.support.v7.widget.Toolbar
        android:id="@+id/activity_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:titleTextColor="@android:color/white">

    </android.support.v7.widget.Toolbar>

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

<km.lmy.searchview.SearchView
     android:elevation="5dp"
     android:id="@+id/searchView"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"/>

License

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

cardsearchview's People

Contributors

limuyang2 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.