0

I want to display the cursor when edit text is touched but soft keyboard must not be displayed. This below code does not displays the cursor when touched. Someone please help me with this. I used samsung galaxy S6 device to test my code

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final EditText edit=(EditText)findViewById(R.id.edit);

    edit.setInputType(InputType.TYPE_NULL);

    edit.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            edit.setCursorVisible(true);
            return false;
        }
    });

}

XML code:

<EditText
    android:layout_width="wrap_content"
    android:id="@+id/edit"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

edit.setInputType(InputType.TYPE_NULL); hides the soft keyboard, but why does edit.setCursorVisible(true); , does not make cursor visible. Is this some device specific. If so how can i solve it?

Suthakar
  • 98
  • 8

1 Answers1

0

In your Manifest.xml

<activity android:name="com.your.package.ActivityName"
  android:windowSoftInputMode="stateHidden"  />

or you can use

  final edit = (EditText) findViewById(R.id.edit);
  edit.setInputType((InputType.TYPE_NULL);