'Android studio custom icon state_focused not working
custom_email_icon.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:drawable="@drawable/ic_email_focused"/>
<item android:state_focused="false"
android:drawable="@drawable/ic_email"/>
</selector>
activity_main.xml
<EditText
android:id="@+id/emailText"
android:layout_width="301dp"
android:layout_height="48dp"
android:layout_marginTop="100dp"
android:ems="10"
android:background="@drawable/custom_input"
android:drawableStart="@drawable/custom_email_icon"
android:drawablePadding="12dp"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:hint="Email Address"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Icon color change not working when I clicked to text. Same problem with the password line.
Solution 1:[1]
Instead of a focused state, you can add a selector for a pressed and selected state like following
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false"
android:state_enabled="true"
android:drawable="@drawable/ic_email" />
<item android:state_window_focused="false"
android:state_enabled="false"
android:drawable="@drawable/ic_email" />
<item android:state_pressed="true"
android:drawable="@drawable/ic_email_focused" />
<item android:state_enabled="true"
android:state_focused="true"
android:drawable="@drawable/ic_email_focused" />
<item android:state_enabled="true"
android:drawable="@drawable/ic_email" />
<item android:state_focused="true"
android:drawable="@drawable/ic_email_focused" />
<item android:drawable="@drawable/ic_email" />
</selector>
Solution 2:[2]
All problem is this code line, I just removed it and fixed; idk why automatically its cames when I add vector.
android:tint="?attr/colorControlNormal"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Kaan Düzbast?lar |
