vs做的网站排版错位,百度 网站改版了,苏州建设交通学校网站首页,网站建设整体方案背景#xff1a;换肤框架下#xff0c;QA进行深色浅色切换说输入框光标颜色没有改变#xff0c;转UI结果UI说需要修改#xff01;#xff01;#xff01;#xff01;#xff01; 本来有方法可以设置#xff0c;但是 设置后未生效。重新进入该页面才生效#xff01;换肤框架下QA进行深色浅色切换说输入框光标颜色没有改变转UI结果UI说需要修改 本来有方法可以设置但是 设置后未生效。重新进入该页面才生效
mView.setTextCursorDrawable(drawable);
查看内部方法 通过Editor的loadCursorDrawable方法得知此前已经有光标背景了则不会进行重新设置了所以就算你实时通过代码方法setTextCursorDrawable设置了新的mDrawableForCursor由于之前不为null所以不会重新设置所以不会生效。
即 mDrawableForCursor mTextView.getTextCursorDrawable(); 方法不会执行 通过查资料发现只能用反射实现于是就有了下面代码
Drawable drawable SkinCompatVectorResources.getDrawableCompat(mView.getContext(), mTextCursorDrawable);try {// Get the editorField fieldP TextView.class.getDeclaredField(mEditor);fieldP.setAccessible(true);Object editorP fieldP.get(mView);// Set the drawablesfieldP editorP.getClass().getDeclaredField(mDrawableForCursor);fieldP.setAccessible(true);fieldP.set(editorP, drawable);} catch (Exception e) {// TODO: handle exceptione.printStackTrace();}
运行后成功实时设置光标颜色了