vnidens / ClickableEditText

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

License:MIT License


Languages

Language:Java 100.0%