Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText's cursor horizontally

Is it possible to have the cursor of an EditText horizontally disposed and not vertically? I would like to have it like in the following image:

horizontal cursor

I have read some topics were people play with the android:textCursorDrawable, but I need it to style it for Android < 3.0. Any ideas?

EDIT: I am adding the xml of the EditText:

<EditText
    android:id="@+id/edittext1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:cursorVisible="true"
    android:ems="10"
    android:hint="@string/id"
    android:inputType="text"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:textCursorDrawable="@drawable/custom_bottom_cursor" />
like image 596
AlvaroSantisteban Avatar asked Mar 10 '26 23:03

AlvaroSantisteban


2 Answers

I was looking for something similar , but I did not found a solution :( only one idea I had found was to set cursorVisible to false

editText.setCursorVisible(false);

then dynamically append char _ to end of edittext, a set blinking animation to end of

Animation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(50); //You can manage the time of the blink with this parameter
anim.setStartOffset(20);
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(Animation.INFINITE);
lastChar.startAnimation(anim);
like image 91
Matej Špilár Avatar answered Mar 12 '26 14:03

Matej Špilár


1) Create a Cursor drawable.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <size 
        android:width="20dp"
        android:height="1dp" />
    <solid
        android:color="#000000" />
    <padding 
        android:top="-20sp"
        android:bottom="1sp" />


</shape>

or however you like.
2) android:textCursorDrawable="@drawable/cursor_drawable"
But this only works with Honeycomb or higher...
Success

like image 44
jyoonPro Avatar answered Mar 12 '26 16:03

jyoonPro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!