├── .github ├── FUNDING.yml └── workflows │ └── mavenPublish.yml ├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── edittext │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── edittext │ │ │ ├── MainActivity.kt │ │ │ └── custom │ │ │ └── ContextWrapper.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── values-ar │ │ └── strings.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── example │ └── edittext │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── materialtextfield ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── zigis │ │ └── materialtextfield │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── zigis │ │ │ └── materialtextfield │ │ │ ├── MaterialTextField.kt │ │ │ └── custom │ │ │ ├── AnimatedRectF.kt │ │ │ └── WrapDrawable.kt │ └── res │ │ ├── drawable-hdpi │ │ ├── ic_clear.png │ │ └── ic_warning.png │ │ ├── drawable-mdpi │ │ ├── ic_clear.png │ │ └── ic_warning.png │ │ ├── drawable-xhdpi │ │ ├── ic_clear.png │ │ └── ic_warning.png │ │ ├── drawable-xxhdpi │ │ ├── ic_clear.png │ │ └── ic_warning.png │ │ ├── drawable-xxxhdpi │ │ ├── ic_clear.png │ │ └── ic_warning.png │ │ ├── drawable │ │ ├── ic_eye_off.xml │ │ ├── ic_eye_on.xml │ │ └── spacer.xml │ │ └── values │ │ ├── attrs.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── zigis │ └── materialtextfield │ └── ExampleUnitTest.java ├── maven ├── publish-module.gradle └── publish-root.gradle ├── sample.gif ├── sample.png └── settings.gradle /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: edgar-zigis 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.github/workflows/mavenPublish.yml: -------------------------------------------------------------------------------- 1 | name: Maven Publish 2 | 3 | on: 4 | release: 5 | types: [ released ] 6 | 7 | jobs: 8 | Maven-Publish: 9 | name: Publish to MavenCentral 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout code 13 | uses: actions/checkout@v1 14 | 15 | - name: Setup JDK 17 16 | uses: actions/setup-java@v3 17 | with: 18 | java-version: '17' 19 | distribution: 'temurin' 20 | 21 | - name: Publish to MavenCentral 22 | run: ./gradlew publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository 23 | env: 24 | OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} 25 | OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} 26 | SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }} 27 | MAVEN_SIGNING_KEY_ID: ${{ secrets.MAVEN_SIGNING_KEY_ID }} 28 | MAVEN_SIGNING_KEY_PASSWORD: ${{ secrets.MAVEN_SIGNING_KEY_PASSWORD }} 29 | MAVEN_SIGNING_KEY: ${{ secrets.MAVEN_SIGNING_KEY }} 30 | SDK_RELEASE_VERSION: ${{ github.event.release.tag_name }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | .DS_Store 5 | /build 6 | /.idea/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Edgar Žigis 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MaterialTextField [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.bio-matic/materialtextfield/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.bio-matic/materialtextfield) 2 | 3 | Custom EditText which follows the latest Material guidelines with animated underline and custom error settings. 4 | ##### Minimum target SDK: 21. RTL SUPPORTED. 5 | 6 | ![alt text](https://github.com/edgar-zigis/MaterialTextField/blob/master/sample.gif?raw=true) 7 | 8 | ### Gradle 9 | Make sure you have **Maven Central** included in your gradle repositories. 10 | 11 | ```gradle 12 | allprojects { 13 | repositories { 14 | mavenCentral() 15 | } 16 | } 17 | ``` 18 | ```gradle 19 | implementation 'com.bio-matic:materialtextfield:1.4.7' 20 | ``` 21 | ### Proguard 22 | In order to preserve underline animation, please include this into proguard file. 23 | 24 | ```proguard 25 | -keep class com.zigis.materialtextfield.** { *; } 26 | ``` 27 | ### Usage 28 | ``` xml 29 | 33 | android:hint="E-mail" 34 | android:text="admin@bio-matic.com" 35 | app:togglePasswordVisibility="true" 36 | app:isMultilineField="true" 37 | app:underlineHeight="1.5dp" 38 | app:isClearEnabled="true" 39 | app:rightIcon="@drawable/ic_clear" 40 | app:rightButtonColor="@color/grey" 41 | app:cursorDrawableColor="@color/colorAccent" 42 | app:defaultHintColor="@android:color/darker_gray" 43 | app:activeHintColor="@android:color/holo_blue_dark" 44 | app:defaultUnderlineColor="@android:color/darker_gray" 45 | app:activeUnderlineColor="@android:color/holo_blue_dark" 46 | app:errorColor="@android:color/holo_red_dark" /> 47 | ``` 48 | ### Remarks 49 | At the moment height is automatically overriden to match original Material guideline height. Also consider using margins instead of padding. 50 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id "com.android.application" 3 | id 'org.jetbrains.kotlin.android' 4 | } 5 | 6 | android { 7 | 8 | namespace 'com.example.edittext' 9 | compileSdk 35 10 | 11 | defaultConfig { 12 | applicationId "com.zigis.materialtextfield.sample" 13 | minSdkVersion 21 14 | targetSdkVersion 35 15 | versionCode 1 16 | versionName "1.0" 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | 26 | buildFeatures { 27 | viewBinding true 28 | } 29 | 30 | compileOptions { 31 | sourceCompatibility JavaVersion.VERSION_17 32 | targetCompatibility JavaVersion.VERSION_17 33 | } 34 | 35 | kotlinOptions { 36 | jvmTarget = '17' 37 | } 38 | } 39 | 40 | dependencies { 41 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 42 | implementation 'androidx.appcompat:appcompat:1.7.0' 43 | implementation 'androidx.constraintlayout:constraintlayout:2.2.1' 44 | implementation project(':materialtextfield') 45 | } 46 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/edittext/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.example.edittext 2 | 3 | import androidx.test.InstrumentationRegistry 4 | import androidx.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("com.example.edittext", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/edittext/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.edittext 2 | 3 | import android.content.Context 4 | import androidx.appcompat.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.view.LayoutInflater 7 | import androidx.core.content.ContextCompat 8 | import com.example.edittext.custom.ContextWrapper 9 | import com.example.edittext.databinding.ActivityMainBinding 10 | import java.util.* 11 | 12 | class MainActivity : AppCompatActivity() { 13 | 14 | override fun onCreate(savedInstanceState: Bundle?) { 15 | super.onCreate(savedInstanceState) 16 | ActivityMainBinding.inflate(LayoutInflater.from(this)).apply { 17 | setContentView(root) 18 | button.setOnClickListener { 19 | password.isLight = false 20 | password.error = resources.getString(R.string.floating_error_incorrect_password) 21 | password.errorColor = ContextCompat.getColor(this@MainActivity, R.color.colorAccent) 22 | } 23 | } 24 | } 25 | 26 | override fun attachBaseContext(newBase: Context) { 27 | val context = ContextWrapper.wrap(newBase, Locale("en")) // for RTL testing use "ar" 28 | super.attachBaseContext(context) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/edittext/custom/ContextWrapper.kt: -------------------------------------------------------------------------------- 1 | package com.example.edittext.custom 2 | 3 | import android.content.Context 4 | import android.os.Build 5 | import android.os.LocaleList 6 | import java.util.* 7 | 8 | class ContextWrapper(base: Context) : android.content.ContextWrapper(base) { 9 | 10 | companion object { 11 | fun wrap(context: Context, newLocale: Locale): ContextWrapper { 12 | var newContext = context 13 | val configuration = newContext.resources.configuration 14 | configuration.setLocale(newLocale) 15 | Locale.setDefault(newLocale) 16 | 17 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 18 | val localeList = LocaleList(newLocale) 19 | LocaleList.setDefault(localeList) 20 | configuration.setLocales(localeList) 21 | } 22 | 23 | newContext = newContext.createConfigurationContext(configuration) 24 | return ContextWrapper(newContext) 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32 | 34 | 36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 66 | 68 | 70 | 72 | 74 | 75 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 18 | 30 | 31 | 32 | 43 | 44 |