Android, how do I stop a pointer appearing below an EditText

前端 未结 4 784
無奈伤痛
無奈伤痛 2020-12-04 02:09

I have an activity with some EditTexts in it. When I click on an EditText to change the text in it a blue arrow appears below where the cursor appears. How can I stop this a

相关标签:
4条回答
  • 2020-12-04 02:35

    As MarvinLabs pointed out, it's a set of drawables in the Android SDK. They can be overridden though.

    1. Find these images in your sdk platform:

      • text_select_handle_left.png
      • text_select_handle_middle.png
      • text_select_handle_right.png
    2. Copy them over to your drawables folder, so you have a local copy to reference. You can change the colors of these, make them empty, or whatever you want. Note that this as MarvinLabs said, it might not be wise to remove them completely because they help the user select text for cutting and copying.

    3. If you don't have a custom theme yet defined in your styles.xml, define one. Then add these items to it:

    _

    <style name="CustomTheme" parent="@android:style/Theme.Holo.Light">
      <item name="android:textSelectHandleLeft">@drawable/text_select_handle_left</item>
      <item name="android:textSelectHandleRight">@drawable/text_select_handle_right</item>
      <item name="android:textSelectHandle">@drawable/text_select_handle_middle</item>
    </style>
    

    BEFORE:

    before

    AFTER:

    after

    (different EditTexts but you get the idea)

    0 讨论(0)
  • 2020-12-04 02:36

    This pointer is a system helper to allow the user to move the cursor easily (more precisely than just by touching the EditText). So I don't know if you can remove it, but I am sure it is not a good idea anyway.

    Additionally, this is the kind of pointer that will get styled differently according to the devices. If you look at the SDK's android source, you will find some drawables called text_select_handle_XXX.png I guess you will find from that how to change the system style in your own theme.

    0 讨论(0)
  • 2020-12-04 02:52

    I'm pretty sure this is only happening on that specific API or device. It might work differently on other apps too. Ultimately I don't see any real way to disable something that is native to the device. Also, the devices out there is very vast so you'd have a very hard time disabling that even if you find a way.

    0 讨论(0)
  • 2020-12-04 02:56

    You can do this programmatically with a custom EditText. You need to create a custom MovementMethod implementation, one such that canSelectArbitrarily() returns false. Then you simply override EditText.getDefaultMovementMethod() to return your CustomMovementMethod:

    public class MyEditText extends EditText {
        private CustomMovementMethod customMovementMethod = new CustomMovementMethod();
        @Override 
        public MovementMethod getDefaultMovementMethod() {
            return customMovementMethod;
        }
    }
    
    private class CustomMovementMethod implements MovementMethod {
    
        @Override
        public boolean canSelectArbitrarily() {
            return false;
        }
    
        @Override
        public void initialize(TextView widget, Spannable text) {
            // TODO Auto-generated method stub
    
        }
    
        @Override
        public boolean onGenericMotionEvent(TextView widget, Spannable text, MotionEvent event) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public boolean onKeyDown(TextView widget, Spannable text, int keyCode, KeyEvent event) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public boolean onKeyOther(TextView view, Spannable text, KeyEvent event) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public boolean onKeyUp(TextView widget, Spannable text, int keyCode, KeyEvent event) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public void onTakeFocus(TextView widget, Spannable text, int direction) {
            // TODO Auto-generated method stub
    
        }
    
        @Override
        public boolean onTouchEvent(TextView widget, Spannable text, MotionEvent event) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public boolean onTrackballEvent(TextView widget, Spannable text, MotionEvent event) {
            // TODO Auto-generated method stub
            return false;
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题