Git Product home page Git Product logo

clearedittext's Introduction

###带清除按钮的 EditText

在输入框中输入内容后会在输入框右侧自动显示清除按钮,点击可清空输入框文本。

清除按钮的样式可以自定义,设置方法如下:
在代码中设置:
editText.setIconClear(R.drawable.ic_clear);
也可在布局文件中设置:
app:iconClear="@drawable/ic_clear"

需要注意两点:

  1. 清除按钮会占据 drawableRight 的位置,所以 ClearEditText 设置 drawableRight 属性无效果;
  2. ClearEditText 中实现了默认的 TextWatcher,便于更新清除按钮显示状态, 如果要设置自定义的 TextWatcher,需要在接口方法 afterTextChanged(Editable s) 调用 editText.updateIconClear(); ,此方法用于更新清除按钮状态。

显示效果:
输入内容前 输入内容后

clearedittext's People

Contributors

liruchun333 avatar

Watchers

 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.