Unable to customize EditText look to select handle / anchor on landscape

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:

 <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <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:

enter image description here

+5
source share
6 answers
  <EditText android:imeOptions="flagNoFullscreen" /> 

You can use android:imeOptions to tell the system not to display user interface editing in full screen mode. enter image description here

+3
source

I think your own EditText descriptor can only be implemented using xml.

  • Define a descriptor style in your styles.xml:

     <style name="CustomSelectHandle"> <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> 
  • Add a style attribute to your EditText:

     <EditText android:id="@+id/edit1" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp" android:text="Hello World" style="@style/CustomSelectHandle" android:textSize="20sp" /> 

I just quickly checked this on a KitKat device, and there were custom descriptors there.

Update: I duplicated the landscape mode issue on my KitKat phone. However, the error does not affect all devices. In particular, when I ran the code in landscape mode on the tablet, user descriptors worked fine.

Additional observation: In the EditText tag that I tested, a background image was also highlighted. This affordable option looks as expected in both portrait and landscape modes, both on phones and tablets. However, if I actually edit the field in landscape mode on the phone, the user background disappears and the field has a simple white background until I leave the editing mode.

Assumed: It seems that Android is launching a different code path (which ignores native formatting) when editing fields in landscape mode on small devices. When the soft keyboard is displayed in landscape mode, it does not leave much space for displaying an editable field on the phone. So, perhaps, the developers at some point made a compromise (so that it would be better to display a very simple text field for editing by the user than to risk that the entire field was closed). Without delving into the source code, this is my best guess about what's happening here ...

+2
source

Below code works fine on Nougat

 <EditText android:layout_width="match_parent" style="@style/MyCustomTheme" android:text="@string/app_name" android:layout_height="wrap_content" /> <style name="MyCustomTheme" parent="@style/AppTheme"> <item name="android:textSelectHandle">@android:drawable/arrow_down_float</item> <item name="android:textSelectHandleLeft">@android:drawable/arrow_down_float</item> <item name="android:textSelectHandleRight">@android:drawable/arrow_down_float</item> </style> 
+2
source

You guys only work in portraiture (just like me). My application is just a landscape, and I looked around, and it looks like an OS error. I notified Google about this. However, if there is a workaround using EditText, 50 points is still suitable for captures.

+2
source

add the XML attribute to your EditText

 android:textColorHighlight="@color/accent_translucent" 
+2
source

Try to add

 <item name="colorControlActivated">@drawable/small_rect</item> 

to your styles

+2
source

Source: https://habr.com/ru/post/1268494/


All Articles