自定义edittext上的光标颜色不正确

时间:2015-05-20 21:21:55

标签: android android-edittext autocompletetextview

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

这是我的自定义类:

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" />

2 个答案:

答案 0 :(得分:2)

如果您正在使用support-v7 AppCompat个库,那么您的所有自定义视图都应扩展其AppCompat对应的视图。尝试扩展AppCompatAutoCompleteTextView

Source

答案 1 :(得分:0)

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

由于您更改主题,光标可能已更改。

相关问题