做横竖屏切换时发现,edittext在切换时游标消失,通过设置EditText.setCursorVisible()和EditText.setFocusable()都没有效果,最后查源码发现通过EditText.requsetFocus()可以实现效果
/** * Call this to try to give focus to a specific view or to one of its * descendants. * * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns * false), or if it is focusable and it is not focusable in touch mode * ({@link #isFocusableInTouchMode}) while the device is in touch mode. * * See also {@link #focusSearch(int)}, which is what you call to say that you * have focus, and you want your parent to look for the next one. * * This is equivalent to calling {@link #requestFocus(int, Rect)} with arguments * {@link #FOCUS_DOWN} and <code>null</code>. * * @return Whether this view or one of its descendants actually took focus. */ public final boolean requestFocus() { return requestFocus(View.FOCUS_DOWN); }
本文介绍了解决Android开发中EditText在屏幕旋转时游标消失的问题。通过调用requestFocus()方法,确保EditText在屏幕方向改变后仍能保持焦点,从而使得光标可见。
525

被折叠的 条评论
为什么被折叠?



