How do I display only the cursor but not the standard Android keyboard when i click on EditText?

How do I display only the cursor but not the standard Android keyboard when i click on EditText?

I want to set, in java code, my EditText so that, when i click will display only the Cursor but not the android standard keyboard. How can I do this? Thanks

I EDITED:

I have an array of EditText:

for (i=0;i<N*N;i++) {
    value[i].setOnTouchListener(this);
    value[i].setOnClickListener(this);
    value[i].setOnFocusChangeListener(this);
}

and this method:

@Override
public void onClick(View v) {
    for (i =0 ; i < N*N; i++) {

        if(v == value[i]) {
        variable = 1;
        if(jey!=i) {
            jey=i;
            showDialog(CUSTOM_DIALOG);
            }
        }
    }
}

@Override
public void onTouch(View v, MotionEvent event) {
    for (i =0 ; i < N*N; i++) {

        if(v == value[i]) {
        variable = 1;
        if(jey!=i) {
            jey=i;
            showDialog(CUSTOM_DIALOG);
            }
        }
    }
}

@Override
public void onFocusChange(View v, boolean hasFocus) { 
    for (i =0 ; i < N*N; i++){
        if(v == value[i]) {
            variable =1;
            if(jey!=i) {
                jey=i;
                imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(value[jey].getWindowToken(), 0);
            }
        }
    }
}

but in this way does not work I still see the standard keyboard


To apply it for one EditText (not for Activity how tell other answers), just provide hiding in focusChangeListener.

mEditText.setOnFocusChangeListener(new CustomListener());

and CustomListener:

protected class CustomListener implements View.OnFocusChangeListener {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
    }
}

You can check hasFocus and hide only if it's true.

Specify the input method type, Specify the keyboard type; Enable spelling suggestions and other behaviors; Specify the for your text fields by adding the android:inputType attribute to the < EditText> element. Here's a layout with only the text field: is a layout provided by Android that provides a standard appearance for text in a list). void MyEditText_Click(object sender, EventArgs e) { _myEditText.SetCursorVisible(true); } I have tried using the FocusChanged event, but it only works for enabling the cursor. It doesn't fire when the keyboard is dismissed. I have tried using the TextChanged event, but the cursor remains if you dismiss the keyboard without changing the text.


Or use this:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

Edit:

This is a common solution I found on other threads:

public class NoImeEditText extends EditText {

     public NoImeEditText(Context context, AttributeSet attrs) { 
          super(context, attrs);     
     }  

     @Override      
     public boolean onCheckIsTextEditor() {   
          return false;     
     }        
} 

Since this is my third try and I'm starting to feel stupid, I personnaly tested this time, and it works. Don't forget to also change the type in your layout, if you use one.

TextView, android:cursorVisible, Makes the cursor visible (the default) or invisible. android:keyboardNavigationCluster, Whether this view is a root of a keyboard navigation cluster. Callback#onKeyUp(int, KeyEvent) : perform clicking of the view when Note that this feature is not supported by EditText, works only for TextView. The EditText is the standard text entry widget in Android apps. If the user needs to enter text into an app, this is the primary way for them to do that. There are many important properties that can be set to customize the behavior of an EditText. Several of these are listed below.


Here you go.

/**
 * EditText which suppresses IME show up.
 */
public class DigitsEditText extends EditText {
    public DigitsEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        setInputType(getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    }

    @Override
    protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
        super.onFocusChanged(focused, direction, previouslyFocusedRect);
        final InputMethodManager imm = ((InputMethodManager) getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE));
        if (imm != null && imm.isActive(this)) {
            imm.hideSoftInputFromWindow(getApplicationWindowToken(), 0);
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        final boolean ret = super.onTouchEvent(event);
        // Must be done after super.onTouchEvent()
        final InputMethodManager imm = ((InputMethodManager) getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE));
        if (imm != null && imm.isActive(this)) {
            imm.hideSoftInputFromWindow(getApplicationWindowToken(), 0);
        }
        return ret;
    }

    @Override
    public void sendAccessibilityEventUnchecked(AccessibilityEvent event) {
        if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED) {
            // Since we're replacing the text every time we add or remove a
            // character, only read the difference. (issue 5337550)
            final int added = event.getAddedCount();
            final int removed = event.getRemovedCount();
            final int length = event.getBeforeText().length();
            if (added > removed) {
                event.setRemovedCount(0);
                event.setAddedCount(1);
                event.setFromIndex(length);
            } else if (removed > added) {
                event.setRemovedCount(1);
                event.setAddedCount(0);
                event.setFromIndex(length - 1);
            } else {
                return;
            }
        } else if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
            // The parent EditText class lets tts read "edit box" when this View has a focus, which
            // confuses users on app launch (issue 5275935).
            return;
        }
        super.sendAccessibilityEventUnchecked(event);
    }
}

Handle input method visibility, Overview � Detect common gestures � Track touch and pointer For most apps, these default behaviors are all that's needed. in your layout when the activity starts, it does not show the input method. Note: If the user's device has an attached hardware keyboard, the soft input method does not appear. Android Quick Tip. Close the keyboard when you click ‘DONE’… seems like a simple task, right? Unfortunately, clicking ‘DONE’ or the ‘RETURN’ button in even a single line Android EditText will not drop focus and close the soft keyboard. In most cases it will just generate a new line of text.


Best solution from @Lupsaa here:

Setting the flag textIsSelectable to true disables the soft keyboard.

You can set it in your xml layout like this:

<EditText
android:id="@+id/editText"
...
android:textIsSelectable="true"/>

Or programmatically, like this:

EditText editText = (EditText) findViewById(R.id.editText);

editText.setTextIsSelectable(true);

The cursor will still be present, you'll be able to select/copy/cut/paste but the soft keyboard will never show.

Creating a Search Interface, By default, the search widget behaves like a standard EditText widget and doesn' t do The android:label attribute is the only required attribute. in many ways, but this guide does not show you how to store your data and search it. the user starts typing on the keyboard—the keystrokes are inserted into the search dialog. The Android system shows an on-screen keyboard—known as a soft input method—when a text field in your UI receives focus.To provide the best user experience, you can specify characteristics about the type of input you expect (such as whether it's a phone number or email address) and how the input method should behave (such as whether it performs auto-correct for spelling mistakes).


public void hideSoftKeyboard() {
    if(getCurrentFocus()!=null) {
        InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
    }
}

public void showSoftKeyboard(View view) {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
view.requestFocus();
inputMethodManager.showSoftInput(view, 0);
}

When you want to show keyboard, just call (showSoftKeyboard()) and when you want to hide keyboard, just call (hideSoftKeyboard()).

Then, just Add another same size layout on edittext and click event on it,then after you unable to click on edittext.

               <EditText
                    android:id="@+id/etAnswer"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@android:color/transparent"
                    android:cursorVisible="false"
                    android:inputType="number"
                    android:maxLength="6"
                    android:maxLines="1"
                    android:paddingLeft="10dp"
                    android:singleLine="true"
                    android:textSize="20sp" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:onClick="onClick" />

Only showing the cursor of an EditText when the keyboard is visible , Only showing the cursor of an EditText when the keyboard is visible (so it is being starting from P, the view will not take focus if it has 0 area (width or height is 0). the details, but basically I argued for a change based on Android standards,� Try the keyboard app AI.TYPE KEYBOARD. Long-pressing 4 of the keys provides forward/back/up/down movement. In addition, there are 2 other ways to easily move the cursor plus enhanced copy/paste and other options.


Android Hide Soft Keyboard from EditText while not losing cursor, When click on editText show the android keyboard (Android forum at , It should show when the user clicks on the EditText by default (when the field gets focus, the keyboard shows). It only hides the cursor when you are not editing it. @ JoJo� The only way to focus EditText No 8 is to hide the keyboard, scroll down and click EditText No 8. You can scroll up without hiding the keyboard. If you set android:windowSoftInputMode="adjustResize", the top portion of the activity (Toolbar/Appbar) is maintained with EditText pushed to above the keyboard.


How to Stop EditText from gaining focus at Activity startup in Android, There are so many situations where we don't required keyboard visibility when activity starts. By Default it contains request focus. edit text is not focusing. now click on edit text, it will show keyboard as shown below -. Google has a clever trick for quickly and easily positioning a cursor with its Android keyboard and the fairly new Gboard keyboard for iOS users. To move the cursor when typing in any text field


Xamarin.Forms Entry, The Entry , like the Editor view, supports multiple keyboard types. The Entry can be set to show placeholder text when it is not storing user input. The default value of the CursorPosition property is 0, which indicates that text will be inserted Screenshot of an Entry with a clear button, on iOS and Android� Display The On-Screen Keyboard on Android Devices. In a text field (email or a message):simply tap on the text box to make the keyboard display appear. You can also press and hold the menu button for several seconds to display the keypad. With this feature, you should see the keyboard appear on your Android phone.