0

I have an EditText and the cursor is invisible. What can I do to show it? This is the EditText in XML:

<RelativeLayout
        android:id="@+id/text_field"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_margin="7dp"
        android:background="@drawable/box_message" >
    <myApp.EditTextView
        android:id="@+id/text_editor"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignWithParentIfMissing="true"
        android:layout_centerVertical="true"
        android:cursorVisible="true"
        android:textCursorDrawable="@null"
        android:layout_toLeftOf="@+id/send_side"
        android:hint="@string/Enter_message_Hint"
        android:imeOptions="actionSend|flagNoEnterAction"
        android:inputType="textShortMessage|textAutoCorrect|textCapSentences|textMultiLine"
        android:maxLength="1000"
        android:maxLines="3"
        android:nextFocusRight="@+id/send_button"
        android:padding="12dp"
        android:textSize="13sp"/>
</RelativeLayout>

It is a custom EditText that has all 3 constructors.

public EditTextView(Context 
{
this(context, null);
}

public EditTextView(Context context, AttributeSet attributeset)
{
this(context, attributeset, 0);
}

public EditTextView(Context context, AttributeSet attributeset, int defStyle)
{
super(context, attributeset, defStyle);

//set onTouch listener.
}

I already tried without android:textCursorDrawable="@null" and it didn't work.

1
  • I used your code and I can see the cursor visible.Post your full xml file, may be background problem. May 7, 2014 at 12:13

4 Answers 4

1

May be because of your background color the cursor is not visible, try to make the gravity center due to which the cursor will be visible.

android:gravity="center"
2
  • That didn't work. I even set the background to green and it didn't work.
    – Scorpio
    May 7, 2014 at 13:18
  • try to keep normal edittext, like only its height and width and gravity and see if its appearing. Then try to add your other attributes.
    – Ajinkya S
    May 7, 2014 at 13:24
0

The code you posted seems correct, so the Problem lies somewhere beyond this scope. I had this problem once and it was due to the wrong context with which I called the constructor. You can check if you actually call the Constructor with the right Application Context. I am afraid, though, that the Problem probably lies somewhere else.

0

The cursor is displayed when EditText's state is "focused". Make sure that the EditText is focusable. Try to add following attributes: android:focusable="true" android:focusableInTouchMode="true". But I think that the problem can be in code of your custom EditText.

0

Set some value to minWidth in xml 1,2,3.. Ex:minWidth="1px" to your EditText's xml

<myApp.EditTextView
minWidth="1px"
.
.
./>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.