光标的颜色(有些手机是不支持光标颜色的设置的比如:华为手机)
在drawable文件夹下新建login_editview_cursor_color.xml,内容如下
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="@color/color_fa1155" /> <size android:width="1dp"/> </shape>
输入的editView内容:
<EditText android:id="@+id/login_verify_mobile" android:layout_width="match_parent" android:layout_height="55dp" android:layout_gravity="center_vertical" android:background="#ffffff" android:gravity="center_vertical" android:hint="请输入手机号" android:inputType="number" android:maxLines="1" android:textCursorDrawable="@drawable/login_editview_cursor_color" android:paddingLeft="15dp" android:paddingStart="15dp" android:textColor="#222222" android:textColorHint="#CCCCCC" android:textSize="14sp" />
如果是在包含fragment的Activity中尽量不要使用 android:windowSoftInputMode="adjustResize|stateHidden",隐藏软键盘,容易出现弹出和隐藏的黑屏
现象。可以在代码中这是editView 的焦点为false来隐藏软键盘。
mMobileNumber.setCursorVisible(false);//隐藏光标 mMobileNumber.setFocusable(false);//失去焦点 mMobileNumber.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mMobileNumber.setFocusable(true); mMobileNumber.setCursorVisible(true); mMobileNumber.setFocusableInTouchMode(true); mMobileNumber.requestFocus(); //打开软键盘 InputMethodManager inputManager = (InputMethodManager) mMobileNumber.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(mMobileNumber, 0); } });
还有一种在弹软键盘和隐藏软件盘的时候,有fragment的情况,也可以更换theme来进行。参考http://blog.csdn.net/hjj395139289/article/details/53309417