Android 自定义编辑文本上的光标颜色不正确
我试图覆盖AutoCompleteTextView,字段中的光标现在为白色。由于明亮的灰色背景,很难识别它们。我不明白怎么可能,我没有设置任何自定义样式,其他字段都可以,并显示standart绿色光标 这是我的自定义类:Android 自定义编辑文本上的光标颜色不正确,android,android-edittext,autocompletetextview,Android,Android Edittext,Autocompletetextview,我试图覆盖AutoCompleteTextView,字段中的光标现在为白色。由于明亮的灰色背景,很难识别它们。我不明白怎么可能,我没有设置任何自定义样式,其他字段都可以,并显示standart绿色光标 这是我的自定义类: public class CustomerAutoCompleteTextView extends AutoCompleteTextView { NewTransactionDialogFragment dialog; public CustomerAuto
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
谢谢您的回复!我没有设置任何主题,只有背景,但其他字段有相同的背景,光标是绿色的。我不能设置textCursorDrawable,因为我的minSDK是9Yeah!非常感谢。这对我来说真的不是很明显。现在它工作正常,我的光标再次变为绿色。