转载请标明:大飞_rflyee http://blog.csdn.net/rflyee/article/details/50810025
一个界面中多个edittext,默认第二个获取焦点(第三个、第四个同理,其他view也同理)
(1)默认第一个获取键盘焦点,因此需要将第一个edittext设置为focusableInTouchMode = false。这样第一个就不会默认获取焦点
android:focusableInTouchMode="false"
(2)触摸第一个edittext时,再将其focusableInTouchMode 置为true即可
editText.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
editText.setFocusableInTouchMode(true);
return false;
}
});
其他edittext相关:
1. edittext禁止调出软键盘(不可编辑,囧)
editText.setFocusable(false);
或者:
editText.setEnable(false);
或者:
editText.setInputType(InputType.TYPE_NULL);来禁止手机软键盘。 (xml中设置inputtype为none不行)
editText.setInputType(InputType.TYPE_CLASS_TEXT);来开启软键盘。
默认调出键盘
(1)清单中设置activity
android:windowSoftInputMode="stateVisible"
(2)代码中设置window
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
2、edittext自定义光标
EditText有一个属性:android:textCursorDrawable,这个属性是用来控制光标颜色的
(1)默认光标颜色和字体颜色一致
(2)android:textCursorDrawable 设置光标图
(3)android:textCursorDrawable="@null",光标颜色和textcolor一样
3、editext光标是否可见
android:cursorVisible="false"
在其父view上设置以下属性即可:
android:focusableInTouchMode="true"
原理:
(1)android系统不仅仅为手机登触摸屏设计,也会有像tv之类的非触摸型(非触摸模式)
(2)focusableInTouchMode便是设置一个view在触摸模式下是否是可以自动获取焦点的
(3)一个界面加载过程中,会从按view tree从上到下寻找第一个在触摸模式下可以自动获取焦点的view.
然后
将焦点给他。所以,将父view设置为可自动获取焦点,那么edittext则不会默认获取焦点了。
(4)focusableInTouchMode和focusable的区别?
android:background="@drawable/bg_chat_keyboard_input_et"
转载请标明:大飞_rflyee http://blog.csdn.net/rflyee/article/details/50810025