Itβs hard for me to tweak the EditText selector. I follow this topic:
How to change color / appearance of an EditText / anchor control?
It looks pretty straight forward. However, I cannot get him to work on the landscape. Can anyone determine what I am doing wrong? I pretty much inserted the same code into the test activity, but the binding handles are "always the same." I tried using styles as suggested and programmatically. However, I always get the same blue supposedly by default :(
I am in Nougat, not sure what matters.
Testing:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTheme(R.style.MyCustomTheme); setContentView(R.layout.activity_main); final EditText editText = (EditText) findViewById(R.id.edit1); // tried programatically too and no success try { final Field fEditor = TextView.class.getDeclaredField("mEditor"); fEditor.setAccessible(true); final Object editor = fEditor.get(editText); final Field fSelectHandleLeft = editor.getClass().getDeclaredField("mSelectHandleLeft"); final Field fSelectHandleRight = editor.getClass().getDeclaredField("mSelectHandleRight"); final Field fSelectHandleCenter = editor.getClass().getDeclaredField("mSelectHandleCenter"); fSelectHandleLeft.setAccessible(true); fSelectHandleRight.setAccessible(true); fSelectHandleCenter.setAccessible(true); fSelectHandleLeft.set(editor, ContextCompat.getDrawable(this, R.drawable.small_rect)); fSelectHandleRight.set(editor, ContextCompat.getDrawable(this, R.drawable.small_rect)); fSelectHandleCenter.set(editor, ContextCompat.getDrawable(this, R.drawable.small_rect)); } catch (final Exception e) { Log.d("CUSTOM_ANCHORS", e.toString()); } }
Markup:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <EditText android:id="@+id/edit1" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp" android:text="Hello World" android:textSize="20sp" /> </LinearLayout>
My styles:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> <style name="MyCustomTheme" parent="@style/AppTheme"> <item name="android:textSelectHandle">@drawable/small_rect</item> <item name="android:textSelectHandleLeft">@drawable/small_rect</item> <item name="android:textSelectHandleRight">@drawable/small_rect</item> </style>
drawable (small_rect.xml)
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <size android:width="20dp" android:height="20dp" /> <gradient android:angle="90" android:centerColor="#D6D6D6" android:endColor="#4B6CD6" android:startColor="#6586F0" /> <corners android:radius="0dp" /> </shape>
result:

source share