EditText光标问题

作者: javalong | 来源:发表于2018-05-04 13:30 被阅读46次

    问题描述 :
    EditText hint内容的字体size大小和实际内容字体size大小不一样,所以采用了这种方式:

     val ss = SpannableString("可提现金额${StringUtils.getPrice(viewModel.balance)}元")//定义hint的值
     val ass = AbsoluteSizeSpan(14, true)//设置字体大小 true表示单位是sp
     ss.setSpan(ass, 0, ss.length, Spanned.SPAN_INCLUSIVE_INCLUSIVE)
     etPrice.hint = SpannedString(ss)
    

    利用spannable设置。

    但是在小米手机上有问题,EditText光标错位,偏上。

    解决办法:

    自定义cursor

    android:textCursorDrawable="@drawable/cursor"
    

    cursor.xml

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <size android:width="2dp" />
        <solid android:color="#222222" />
        <padding
            android:bottom="@dimen/y60"
            android:top="0sp" />
    </shape>
    

    用padding字段,android:bottom="@dimen/y60"具体数值根据自己的实际情况。

    cursor就算过长也不会显示出来,因为整个EditText的高度是一定的不会超出EditText的高度。

    相关文章

      网友评论

        本文标题:EditText光标问题

        本文链接:https://www.haomeiwen.com/subject/dyjdrftx.html