在EditText中更改光标的可绘制

问题描述

我尝试以不同的方式和顺序在afterTextChanged()中更改可绘制光标。 我究竟做错了什么? 在EditText中输入字符后,如何更改光标?

public class View extends ConstraintLayout {
private EditText editText;

 public View (Context context,AttributeSet attrs) {
    super(context,attrs);
    editText = findViewById(R.id.editText);
    editText.setTextCursorDrawable(R.drawable.first_cursor);
    editText.setCursorVisible(true);

    editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence,int start,int count,int after) {}
     
        @Override
        public void onTextChanged(CharSequence charSequence,int before,int count) {}

        @Override
        public void afterTextChanged(Editable s) {
           editText.setCursorVisible(false);
           editText.setTextCursorDrawable(null);
           editText.setTextCursorDrawable(R.drawable.second_cursor);
           requestLayout();
           editText.invalidate();
           invalidate();
           editText.setCursorVisible(true);
 }          

在第二个光标中,我要为其设置填充。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)