When Edittext Is Select, Theme/style Does Not Change
I have Edittext in my signup form. When user touch on edittext then edittext box turn to green( which represent that edittext is selected ) i don't want this. when user select any
Solution 1:
In your styles.xml
<stylename="EditTextTheme"><itemname="colorControlNormal">#ffffff</item></style>
apply theme for edittext
<EditTextandroid:layout_width="match_parent"android:layout_height="wrap_content"android:theme="@style/EditTextTheme"/>
Other solution: Create selector xml file in drawables
<?xml version="1.0" encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"><solidandroid:color="#ffffff" /><strokeandroid:width="1dip"android:color="#ff9900" /></shape>
Add this line in edittext
android:background="@drawable/xml name"
Solution 2:
Go To your styles.xml and change your Application Theme to this:
<stylename="AppTheme"parent="Theme.AppCompat.Light.NoActionBar"><!-- Customize your theme here. --><itemname="colorPrimary">@color/colorPrimary</item><itemname="colorPrimaryDark">@color/colorPrimaryDark</item><itemname="colorAccent">@color/white</item> CHANGE THIS LINE
</style>
Solution 3:
I had issues with changing the global theme, I just wanted one EditText not all of them so the setting the globals styles was not the right answer.
Instead I just did this:
<android.support.design.widget.TextInputEditText
android:id="@+id/car_seller_notes_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hint"
android:maxLength="1000"
android:background="@drawable/edit_text_myunderline"/>
edit_text_myunderline.xml
<?xml version="1.0" encoding="utf-8"?><layer-listxmlns:android="http://schemas.android.com/apk/res/android"><item><shapeandroid:shape="rectangle"><!-- Draw a 2dp width border around shape --><strokeandroid:color="@color/edit_text_underline_color"android:width="2dp" /></shape></item><!-- Overlap the left, top and right border using background color --><itemandroid:bottom="2dp"><shapeandroid:shape="rectangle"><solidandroid:color="@color/window_background"/></shape></item></layer-list>
Solution 4:
Use latest material library
app/build.gradle
implementation 'com.google.android.material:material:1.2.0-alpha06'
styles.xml
<!-- Base application theme. --><stylename="AppTheme"parent="Theme.MaterialComponents.Light.Bridge"><!-- Customize your theme here. -->
...
</style>
layout XML
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:id="@+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
>
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="User Name"
android:text="Chandler"
android:textCursorDrawable="@null"
/>
</com.google.android.material.textfield.TextInputLayout>
Kotlin code
text_input_layout.boxStrokeColor = Color.CYAN
text_input_layout.defaultHintTextColor = ColorStateList.valueOf(Color.YELLOW)
text_input_layout.setErrorTextColor(ColorStateList.valueOf(Color.RED))
text_input_layout.setErrorIconTintList(ColorStateList.valueOf(Color.RED))
edit_text.backgroundTintList = ColorStateList.valueOf(Color.LTGRAY)
When the textfield is focused/selected/highlighted:
Post a Comment for "When Edittext Is Select, Theme/style Does Not Change"