Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Dec 18, 2022. It is now read-only.
/ ClickableEditText Public archive

The library extends Android edit text widgets by adding the ability to treat some compound drawables as buttons.

License

Notifications You must be signed in to change notification settings

vnidens/ClickableEditText

Repository files navigation

ClickableEditText

Release GitHub license

The library extends Android edit text widgets by adding the ability to treat some compound drawables as buttons.

The complete list of extended classes:

  • ClickableEditText
  • ClickableTextInputEditText
  • ClickableAutoCompleteTextView
  • ClickableMultiAutoCompleteTextView

Table of Contents

  1. Sample Project
  2. Gradle Dependency
  3. Drawables
  4. Tinting
  5. Callbacks

Sample Project

You can get the latest APK from this repo or download it from Google Play:

Get it on Google Play

Gradle Dependency

Repository

Add this in your root build.gradle file (not your module build.gradle file):

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

Library dependency

dependencies {
 // other dependencies
 compile('com.github.vnidens:ClickableEditText:0.5.0.5'){
 transitive = true
 }
}

Drawables

Drawables for buttons can be set either from code either in XML.

From code:

 ClickableEditText cet = ...;
 Drawable drawable = ...;
 cet.setStartButtonDrawable(R.drawable.ic_icon);
 cet.setEndButtonDrawable(drawable);

In XML:

 <com.vnidens.clickableedittext.ClickableEditText
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:hint="ClickableEditText"
 app:cet_drawableStart="@drawable/ic_icon"
 app:cet_drawableEnd="@drawable/ic_icon_0"/>

Tinting

You can add tinting for each button separately. The tint can be either a simple color either a color recource or a color state list.

From code:

 ClickableEditText cet = ...;
 ColorStateList colorList = ...;
 
 cet.setStartButtonTintRes(R.color.blue_500);
 cet.setEndButtonTintList(colorList);
 
 ClickableEditText cet1 = ...;
 int color = ...;
 cet1.setStartButtonTint(color);

From XML:

 <com.vnidens.clickableedittext.ClickableEditText
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:hint="ClickableEditText"
 app:cet_drawableStart="@drawable/ic_icon"
 app:cet_drawableStartTint="@color/state_list_blue"
 app:cet_drawableEnd="@drawable/ic_icon_0"
 app:cet_drawableEndTint="@color/blue_500"/>

Callbacks

To get the button click event you should implement OnCompoundButtonClickListner interface and register it for start and/or end button click event.

 ClickableEditText cet = ...;
 OnCompoundButtonClickListner listener = new OnCompoundButtonClickListener(){
 @Override
 public void onCompoundButtonClicked(@NonNull EditText view, @IdRes int which){
 ... 
 }
 };
 cet.setOnStartButtonClickListener(listner);
 cet.setOnEndButtonClickListener(listener);

The view parameter will tell you from which view the event came from. And the which parameter will tell you the button's id which has been clicked.

About

The library extends Android edit text widgets by adding the ability to treat some compound drawables as buttons.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /