I have an EditText in my main layout. I also have an app theme, where the default edittext is styled with a custom curdordrawable.
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/introEditText"
android:gravity="top"
android:singleLine="false"
android:text=""
android:inputType="textMultiLine"
android:textSize="24sp" >
<requestFocus/>
</EditText>
<style name="AppTheme" parent="android:Theme.Holo.NoActionBar">
<item name="android:textColor">#ffffff</item>
...
<item name="android:editTextStyle">@style/EditTextStyle</item>
</style>
<style name="EditTextStyle" parent="@android:style/Widget.EditText">
<item name="android:background">@android:color/transparent</item>
<item name="android:textCursorDrawable">@drawable/cursor</item>
</style>
And my custom cursor is:
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<size android:width="2dp" />
<solid android:color="#363636" />
</shape>
The cursor color is correct, although its width isn't. On the first row it's 1 px wide instead of the 2dp. As soon as the text breaks into two lines, the cursor becomes 2dp wide. Also, it is not shown when the edittext has no text. I tested this on 4.4 (HTC One and a Nexus 7) Is this an Android bug?
Actually as the width of the EditText increases, the cursor's size is set masked by some space(can't figure out what it was). So the solution is to fix the EditText width.
<EditText
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/introEditText"
android:gravity="top"
android:singleLine="false"
android:text=""
android:inputType="textMultiLine"
android:textSize="24" />
If you want exact width, use ems like:
<EditText android:ems="10" ...
/>
android:ems sets the width of a TextView to fit a text of n 'M' letters when the text size 12sp
I don't think there's a way around this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With