自定义编辑文本上的错误光标颜色

Bad cursor color on custom edittext

我试图覆盖 AutoCompleteTextView,字段中的光标现在是白色的。由于明亮的灰色背景,很难识别它们。我不明白怎么可能,我没有设置任何自定义样式,其他字段都可以并显示标准绿色光标。

这是我的习惯 class:

public class CustomerAutoCompleteTextView extends AutoCompleteTextView {

    NewTransactionDialogFragment dialog;

    public CustomerAutoCompleteTextView(Context context) {
        super(context);
    }

    public CustomerAutoCompleteTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomerAutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    @Override
    public boolean onKeyPreIme(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK &&
                event.getAction() == KeyEvent.ACTION_UP) {
                    if(dialog!=null){
                        dialog.showFieldsOverCustomer();
                    }
        }else if(keyCode == KeyEvent.KEYCODE_ENTER &&
                event.getAction() == KeyEvent.ACTION_UP){
            if(dialog!=null){
                dialog.hideKeyboard(); //this part doesn't work if I press ENTER, but it will be my other question
            }
        }
        return super.onKeyPreIme(keyCode, event);

    }


    public void setDialog(NewTransactionDialogFragment dialog){
        this.dialog=dialog;
    }
}

这是我的布局:

<my_package.CustomerAutoCompleteTextView
android:id="@+id/inputCustomer"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="@drawable/apptheme_edit_text_holo_light"
android:hint="@string/hint_customer_email"
android:cursorVisible="true"
android:singleLine="true"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:drawablePadding="10dp"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:imeOptions="actionDone"
android:inputType="none" />

您可以将android:textCursorDrawable属性设置为@null,光标颜色将与您的文本颜色相同。

光标可能因为你改变了主题而改变了。

如果您正在使用 support-v7 AppCompat 库,您所有的自定义视图都应该扩展它们的 AppCompat 对应项。尝试扩展 AppCompatAutoCompleteTextView.

Source