Skip to content

Simple custom EditText which able to clear input with your own icon. That's all.

Notifications You must be signed in to change notification settings

kopihao/KopihaoClearableEditText

Repository files navigation

KopihaoClearableEditText

Simple custom EditText which able to clear input with your own icon. That's all...

Why use this

  1. Purely Android native
  2. Clear icon be customize well

How it behave

  1. When no text, no clear_icon appear.
  2. When there is atleast a character, clear_icon will appear.
  3. Tap on clear_icon, input of CET will be cleared.

How to use

In your Android Layout XML:

<com.view.plugin.cet.ClearableEditText
            android:id="@+id/cetInput"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:background="@android:color/white"
            android:gravity="center_vertical|start"
            android:hint="@string/txt_content"
            android:padding="5dp"
            android:text="@string/app_name"
            android:textSize="20sp" />

In your Android Java:

//Find from layout xml
ClearableEditText cetInput = (ClearableEditText) findViewById(R.id.cetInput);

or

//Declare component
ClearableEditText cetInput = new ClearableEditText(this);

How to customize

Clear Icon (Drawable) can be customized via:

  • Method
  • Extended class

Method :

cetInput.setClearIcon(android.R.drawable.ic_btn_speak_now);

Extended class :

public class YetAnotherCET extends ClearableEditText {

	public YetAnotherCET(final Context context) {
		super(context);
	}

	public YetAnotherCET(final Context context, final AttributeSet attrs) {
		super(context, attrs);
	}

	public YetAnotherCET(final Context context, final AttributeSet attrs, final int defStyle) {
		super(context, attrs, defStyle);
	}

	@Override
	protected void initView(Context context) {
		super.initView(context);
		setClearIcon(android.R.drawable.btn_star_big_on);
	}

}

Things to take note

  • Clear icon will affect CET height.
  • Make sure all icons in various resolution is resized well.

Dependancy

None! Beauty of it? Purely Native.

Preview

Preview1

Live Demo

License

Copyright (C) 2015 Kopihao

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.

About

Simple custom EditText which able to clear input with your own icon. That's all.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages