Coba Kode Di Bawah Ini Berfungsi Dalam Keadaan Normal
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/TextLabel">
<android.support.v7.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hiiiii"
android:id="@+id/edit_id"/>
</android.support.design.widget.TextInputLayout>
Dalam Styles Folder Kode TextLabel
<style name="TextLabel" parent="TextAppearance.AppCompat">
<!-- Hint color and label color in FALSE state -->
<item name="android:textColorHint">@color/Color Name</item>
<item name="android:textSize">20sp</item>
<!-- Label color in TRUE state and bar color FALSE and TRUE State -->
<item name="colorAccent">@color/Color Name</item>
<item name="colorControlNormal">@color/Color Name</item>
<item name="colorControlActivated">@color/Color Name</item>
</style>
Setel ke Tema Utama Aplikasi, Ini Bekerja Hanya Sorot Keadaan Saja
<item name="colorAccent">@color/Color Name</item>
Memperbarui:
UnsupportedOperationException: Tidak dapat mengonversi ke warna: type = 0x2 di api 16 atau di bawah
Larutan
Memperbarui:
Apakah Anda menggunakan Perpustakaan Komponen Bahan
Anda dapat menambahkan baris di bawah ini ke tema utama Anda
<item name="colorPrimary">@color/your_color</item> // Activated State
<item name="colorOnSurface">@color/your_color</item> // Normal State
atau Anda ingin warna yang berbeda dalam keadaan noraml dan keadaan diaktifkan dan dengan kustomisasi ikuti kode di bawah ini
<style name="Widget.App.TextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="materialThemeOverlay">@style/ThemeOverlay.App.TextInputLayout</item>
<item name="shapeAppearance">@style/ShapeAppearance.App.SmallComponent</item> //Changes the Shape Apperance
<!--<item name="hintTextColor">?attr/colorOnSurface</item>--> //When you added this line it will applies only one color in normal and activate state i.e colorOnSurface color
</style>
<style name="ThemeOverlay.App.TextInputLayout" parent="">
<item name="colorPrimary">@color/colorPrimaryDark</item> //Activated color
<item name="colorOnSurface">@color/colorPrimary</item> //Normal color
<item name="colorError">@color/colorPrimary</item> //Error color
//Text Appearance styles
<item name="textAppearanceSubtitle1">@style/TextAppearance.App.Subtitle1</item>
<item name="textAppearanceCaption">@style/TextAppearance.App.Caption</item>
<!--Note: When setting a materialThemeOverlay on a custom TextInputLayout style, don’t forget to set editTextStyle to either a @style/Widget.MaterialComponents.TextInputEditText.* style or to a custom one that inherits from that.
The TextInputLayout styles set materialThemeOverlay that overrides editTextStyle with the specific TextInputEditText style needed. Therefore, you don’t need to specify a style tag on the edit text.-->
<item name="editTextStyle">@style/Widget.MaterialComponents.TextInputEditText.OutlinedBox</item>
</style>
<style name="TextAppearance.App.Subtitle1" parent="TextAppearance.MaterialComponents.Subtitle1">
<item name="fontFamily">@font/your_font</item>
<item name="android:fontFamily">@font/your_font</item>
</style>
<style name="TextAppearance.App.Caption" parent="TextAppearance.MaterialComponents.Caption">
<item name="fontFamily">@font/your_font</item>
<item name="android:fontFamily">@font/your_font</item>
</style>
<style name="ShapeAppearance.App.SmallComponent" parent="ShapeAppearance.MaterialComponents.SmallComponent">
<item name="cornerFamily">cut</item>
<item name="cornerSize">4dp</item>
</style>
Tambahkan baris di bawah ini ke tema utama Anda atau Anda dapat mengatur style ke textinputlayout di xml Anda
<item name="textInputStyle">@style/Widget.App.TextInputLayout</item>