How to change focus color of EditText in Android
You'll have to create/modify your own NinePatch image to replace the default one, and use that as the background of your EditText. If you look in your SDK folder, under your platform, then res/drawable, you should find the NinePatch image for the EditText focus state. If that's all you want to change, you can just pull it into Photoshop, or whatever image editing software you have, and change the orange color to a color of your choosing. Then save that into your drawable folder, and build a new StateListDrawable, for example something like the below:
edittext_modified_states.xml
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:state_pressed="true"
android:drawable="@android:drawable/edittext_pressed"
/> <!-- pressed -->
<item
android:state_focused="true"
android:drawable="@drawable/edittext_focused_blue"
/> <!-- focused -->
<item
android:drawable="@android:drawable/edittext_normal"
/> <!-- default -->
</selector>
I don't know offhand the actual names for the default NinePatches for the EditText, so replace those as necessary, but the key here is to just use the @android:drawable
images for the ones you haven't modified (or you can copy them over to your project's drawable folder), and then use your modified drawable for your focused state.
You can then set this StateListDrawable as the background for your TextView, like so:
<TextView
android:background="@drawable/edittext_modified_states"
Change Edit Text Underline Color to be the same when off focused & focused
You can try adding a theme
<style name="EditTextTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">@color/primary</item>
<item name="colorControlActivated">@color/primary</item>
<item name="colorControlHighlight">@color/primary</item>
</style>
and set it on your EditText
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/EditTextTheme">
</EditText>
EditText changes background color after focus
Please remove the foreground attr.
Change border color when edittext is focused
You can create a custom shape for your EditText
1: STATE_ENABLED is to check if the ET is enabled/disabled.
2: STATE_PRESSED is to check when the ET is pressed (it will change the color on the press but won't keep it that way.)
3: STATE_FOCUSED keeps the ET border color changed as long as the ET is focused(This fulfills the requirement).
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true"
android:state_focused="true">
<shape android:padding="10dp" android:shape="rectangle">
<solid android:color="#FFFFFF" />
<stroke android:width="2dp" android:color="#ffa0a496" />
<corners android:bottomLeftRadius="15dp" android:bottomRightRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp" />
</shape>
</item>
<item android:state_enabled="true">
<shape android:padding="10dp"
android:shape="rectangle">
<solid android:color="#FFFFFF" />
<corners android:bottomLeftRadius="15dp" android:bottomRightRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp" />
</shape>
</item>
</selector>
And set background:
editText.setBackgroundResource(R.drawable.yourFile);
Related Topics
Toolbar Overlapping Below Status Bar
Android - R Cannot Be Resolved to a Variable
Notificationcompat with API 26
How to Change Textcolor in Alertdialog
Add Button to a Layout Programmatically
Mediarecorder and Videosource.Surface, Stop Failed: -1007 (A Serious Android Bug)
How to Use Tools:Overridelibrary in a Build.Gradle File
Android - Best and Safe Way to Stop Thread
Apache Httpclient on Android Producing Certpathvalidatorexception (Issuername != Subjectname)
Quaternion Rotation Does Not Work as Excepted
Android Viewmodel Additional Arguments
Memory Leaks with Custom Font for Set Custom Font
What Is the Intent of the Methods Getitem and Getitemid in the Android Class Baseadapter
Best Practices: Layouts on Android (Programmatic VS Xml)
Retrieving a List of Users Who Have Registered Using Firebase Auth
Android - Spacing Between Checkbox and Text
Android.App Fragments VS. Android.Support.V4.App Using Viewpager