Reputation: 4327
I'm trying to display the cursor in an EditText by adding
android:cursorVisible="true"
in the xml. The issue is that the app version written for a full touch device that use softKeyboard display the cursor but i've developed the app also for devices with physical keyboard and when i'm hidding the softkeyboard the cursor is not even visible.
So the question is how can i make the cursor visible?
For example here is my xml file of an custom Alert and even here the cursor is not showed.
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
android:background="#ffffff"
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="2dp"
android:layout_marginEnd="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:text="Site:"
tools:ignore="HardcodedText" />
<EditText
android:cursorVisible="true"
android:layout_margin="10dp"
android:id="@+id/site"
android:layout_width="match_parent"
android:background="#2323"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@+id/textView"
android:ems="10"
android:textSize="24sp"
android:textColor="#232323"
android:imeOptions="actionDone"
android:inputType="textUri"
tools:ignore="LabelFor" />
<TextView
android:id="@+id/textUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/textView"
android:layout_below="@+id/site"
android:layout_marginTop="5dp"
android:text="User:"
tools:ignore="HardcodedText" />
<EditText
android:cursorVisible="true"
android:id="@+id/editUser"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@+id/textUser"
android:layout_margin="10dp"
android:background="#2323"
android:ems="10"
android:imeOptions="actionDone"
android:inputType="textNoSuggestions"
android:textColor="#232323"
android:textSize="24sp"
tools:ignore="LabelFor" />
<TextView
android:id="@+id/pswFtp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/textView"
android:layout_below="@+id/editUser"
android:layout_marginTop="5dp"
android:text="Password:"
tools:ignore="HardcodedText" />
<EditText
android:cursorVisible="true"
android:layout_margin="10dp"
android:id="@+id/editPswFtp"
android:layout_width="match_parent"
android:background="#2323"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@+id/pswFtp"
android:ems="10"
android:textSize="24sp"
android:textColor="#232323"
android:imeOptions="actionDone"
android:inputType="textNoSuggestions"
tools:ignore="LabelFor" />
<Button
android:id="@+id/save"
android:layout_below="@+id/editPswFtp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#232323"
android:text="SALVA"
tools:ignore="HardcodedText" />
</RelativeLayout>
Upvotes: 1
Views: 3388
Reputation: 4327
Solved by using
editText.setShowSoftInputOnFocus(false);
Instead of
editText.setInputType(InputType.TYPE_NULL);
Upvotes: 3
Reputation: 103
You could just create your custom one that would be visible.
In the res/drawable
make your custom_cursor.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<size android:width="2dp"/>
<solid android:color="@color/colorPrimary"/>
</shape>
and then add it to your EditText
android:textCursorDrawable="@drawable/custom_cursor"
You can select your own colors and size of the cursor.
Upvotes: 0