XEditText Documentation

repository·master·Indexed 19 days ago

https://github.com/woxingxiao/xedittext

A wrapper around the standard Android EditText providing enhanced features such as one-click text clearing, password visibility toggling, text pattern/separator formatting, and emoji disabling. Includes support for AndroidX and standard Support Library projects.

Tokens
725
Snippets
2
Records
3
Agent score
18%

What's inside XEditText

  1. Install XEditText via Gradle

    master

    Depending on whether your project uses AndroidX or the standard support library, add the corresponding dependency to your build.gradle file. Replace ${LATEST_VERSION} with the desired version (e.g., 2.3.0).

    // For AndroidX projects
    dependencies {
        implementation 'com.xw.repo:xedittext-androidx:2.3.0'
    }
    
    // For standard Support Library projects
    dependencies {
        implementation 'com.xw.repo:xedittext:2.3.0'
    }
  2. Use XEditText Listeners

    master

    XEditText requires using its specific listener methods instead of the standard Android EditText listeners to ensure compatibility with its enhanced features.

    • Use .setOnXTextChangeListener() instead of .addTextChangedListener().
    • Use .setOnXFocusChangeListener() instead of .setOnFocusChangeListener().
  3. Configure XEditText via XML attributes

    master

    XEditText provides several custom attributes to enhance standard EditText behavior. Use the app: namespace to access these features.

    Key Attributes:

    • app:x_disableClear: Boolean. Set to true to disable the clear button.
    • app:x_clearDrawable: Drawable (supports Vector Drawables). Customizes the icon used to clear text.
    • app:x_hidePwdDrawable: Drawable. Custom icon for hiding password text.
    • app:x_showPwdDrawable: Drawable. Custom icon for showing password text.
    • app:x_pattern: String. Defines a pattern to separate text content (e.g., "3,4,4").
    • app:x_separator: String. Defines the character used to separate text content based on the pattern.
    • app:x_interactionPadding: Dimension (e.g., 16dp). Customizes the padding of the drawable interaction rect area.

    Note on Password Input: When using custom password drawables, do not set android:gravity to center, center_horizontal, right, or end, otherwise the ClearDrawable will not appear.

    <!-- Example: Password input with custom drawables and pattern separation -->
    <com.xw.repo.XEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="password input, custom drawables"
        android:inputType="textPassword"
        app:x_clearDrawable="@mipmap/ic_clear"
        app:x_hidePwdDrawable="@mipmap/ic_hide"
        app:x_showPwdDrawable="@mipmap/ic_show"
        app:x_pattern="3,4,4"
        app:x_separator=" "/>