Giter VIP home page Giter VIP logo

sudreamer / zedittext Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zrunker/zedittext

0.0 0.0 0.0 201 KB

不一样的EditText(一)DrawableRight清空输入值功能。不一样的EditText(二)DrawableRight显示和隐藏输入密码。不一样的EditText(三)DrawableLeft和DrawableRight的点击事件监听。(四)限制字数,显示输入字数和输入字数。使用工具Android Studio

Java 100.00%

zedittext's Introduction

ZEditText

不一样的EditText(一)DrawableRight清空输入值功能。不一样的EditText(二)DrawableRight显示和隐藏输入密码。不一样的EditText(三)DrawableLeft和DrawableRight的点击事件监听。(四)限制字数,显示剩余字数和输入字数。使用工具Android Studio

引入Android Studio:

1、在build.gradle文件中添加以下代码:

allprojects {
	repositories {
		maven { url 'https://jitpack.io' }
	}
}
dependencies {
	compile 'com.github.zrunker:ZEditText:v1.0.4.5'
}

2、在maven文件中添加以下代码:

<repositories>
	<repository>
		<id>jitpack.io</id>
		<url>https://jitpack.io</url>
	</repository>
</repositories>
<dependency>
	<groupId>com.github.zrunker</groupId>
	<artifactId>ZEditText</artifactId>
	<version>v1.0.4.5</version>
</dependency>

用法:

一、DrawableRight清空输入值功能。

引入布局文件

<cc.ibooker.zedittextlib.ClearEditText
        android:id="@+id/clearEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="text" />

功能实现

// 带清空功能的EditText
ClearEditText clearEditText = (ClearEditText) findViewById(R.id.clearEditText);
// 输入内容改变事件监听
clearEditText.setOnTextChangedListener(new ClearEditText.OnTextChangedListener() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
});

二、DrawableRight显示和隐藏输入密码。

引入布局文件

<cc.ibooker.zedittextlib.PasswdEditText
        android:id="@+id/passwdEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword" />

三、DrawableLeft和DrawableRight的点击事件监听。

引入布局文件

<cc.ibooker.zedittextlib.DrawableEditText
        android:id="@+id/drawableEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawableEnd="@mipmap/icon_reduce"
        android:drawableLeft="@mipmap/icon_add"
        android:drawableRight="@mipmap/icon_reduce"
        android:drawableStart="@mipmap/icon_add"
        android:inputType="number" />

功能实现

// 带Drawable监听的EditText
final DrawableEditText drawableEditText = (DrawableEditText) findViewById(R.id.drawableEditText);
drawableEditText.setGravity(Gravity.CENTER);
drawableEditText.setOnDrawableLeftListener(new DrawableEditText.OnDrawableLeftListener() {
            @Override
            public void onDrawableLeftClick() {
                Toast.makeText(MainActivity.this, "左侧点击", Toast.LENGTH_SHORT).show();
                drawableEditText.setText(Integer.parseInt(drawableEditText.getText().toString()) - 1);
            }
        });
drawableEditText.setOnDrawableRightListener(new DrawableEditText.OnDrawableRightListener() {
            @Override
            public void onDrawableRightClick() {
                Toast.makeText(MainActivity.this, "右侧点击", Toast.LENGTH_SHORT).show();
                drawableEditText.setText(Integer.parseInt(drawableEditText.getText().toString()) + 1);
            }
});

四、限制字数,显示剩余字数和输入字数。

引入布局文件

<cc.ibooker.zedittextlib.LimitNumEditText
        android:id="@+id/limitNumEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp" />

功能实现

// 带输入字数限制和显示输入字数的EditText
LimitNumEditText limitNumEditText = (LimitNumEditText) findViewById(R.id.limitNumEditText);
limitNumEditText.setEditTextSize(16)
                .setEditTextMargin(20, 20, 20, 20)
                .setEditTextColor("#FF0Fad")
                .setEditTextLineNum(5)
                .setEditTextMaxLines(10)
                .setEditTextHint("你好啊")
                .setEditTextHintColor("#405ff2")
                .setEditTextMaxWordsNum(10)
                .setTextViewSize(16)
                .setTextViewColor("#894563")
                .setTextViewMargin(15, 15, 15, 15)
                .setOnMoreMaxWordsNumListener(new LimitNumEditText.OnMoreMaxWordsNumListener() {
                    @Override
                    public void onMoreMaxWordsNum(int maxNum) {
                        Toast.makeText(MainActivity.this, "你已经超过最大字数", Toast.LENGTH_SHORT).show();
                    }
                });

zedittext's People

Contributors

zrunker 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.