/ TextView

A simple and flexible Checked TextView or Checkable TextView

A simple and flexible Checked TextView or Checkable TextView

CheckableTextView

A simple and flexible Checked TextView or Checkable TextView written in Kotlin.

CheckableTextView

Installation

  1. Add it in your root build.gradle at the end of repositories:
	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}
  1. Add the dependency in app gradle
	dependencies {
	        implementation 'com.github.JDevZone:CheckableTextView:{latest_version}'
	}

Basic usage

<com.devzone.checkabletextview.CheckableTextView
            android:layout_marginTop="20dp"
            android:background="#e8e8e8"
            app:ctv_TextStyle="@style/TextAppearance.General"
            app:ctv_IconTint="@color/colorAccent"
            app:ctv_IconChecked="true"
            app:ctv_Icon="@drawable/ic_cancel_custom_vector"
            app:ctv_Text="@string/app_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

Change State Programatically

You can change checked state as follows :

checkedTV.setChecked(isChecked)

Default value shouldNotifyListeners is false

or

checkedTV.setChecked(isChecked,shouldNotifyListeners)

First Boolean parameter isChecked sets the current state
Second Boolean parameter shouldNotifyListeners determines
if onCheckChange method should be called or not.

Listen State Changes

You can listen to state changes by registering a listener like as follows :

checkedTV.setOnCheckChangeListener()

and get callback in implemented method :

override fun onCheckChange(view: View, isChecked: Boolean) {
        // checkedTV returned as view
        // isChecked current state of the view
    }

Customisation

Here are the attributes you can specify through XML or related setters:

  • ctv_Text - Set text.
  • ctv_TextSize - Set text size.
  • ctv_TextColor - Set text color.
  • ctv_TextStyle - Set text style.
  • ctv_Icon - Set custom icon.
  • ctv_IconTint - Set icon tint.
  • ctv_IconChecked - Set textView state checked.

GitHub