Android之EditText特殊小技巧
一、横屏时,弹出软键盘不全屏
不知你是否注意到,当我们手机横屏,且使用Android自带的软键盘为EditText进行文本输入时,若不进行特殊的设置,该软键盘会占用整个界面,那么,如何让键盘只占用屏幕的一部分呢?其实只需要改一个小小的属性即可!
[html] view plain copy print ?- <EditText
- android:id="@+id/text1"
- android:layout_width="150dip"
- android:layout_height="wrap_content"
- android:imeOptions="flagNoExtractUi"/>
<EditText android:id="@+id/text1" android:layout_width="150dip" android:layout_height="wrap_content" android:imeOptions="flagNoExtractUi"/>
另外使用android:imeOptinos可对Android自带的软键盘进行一些界面上的设置:
android:imeOptions="flagNoExtractUi" //使软键盘不全屏显示,只占用一部分屏幕
同时,这个属性还能控件软键盘右下角按键的显示内容,默认情况下为回车键
android:imeOptions="actionNone" //输入框右侧不带任何提示
android:imeOptions="actionGo" //右下角按键内容为'开始'
android:imeOptions="actionSearch" //右下角按键为放大镜图片,搜索
android:imeOptions="actionSend" //右下角按键内容为'发送'
android:imeOptions="actionNext" //右下角按键内容为'下一步'
android:imeOptions="actionDone" //右下角按键内容为'完成'
同时,可能EditText添加相应的监听器,捕捉用户点击了软键盘右下角按钮的监听事件,以便进行处理。
[java] view plain copy print ?- editText.setOnEditorActionListener(newOnEditorActionListener(){
- @Override
- publicbooleanonEditorAction(TextViewv,intactionId,KeyEventevent){
- Toast.makeText(MainActivity.this,"text2",Toast.LENGTH_SHORT).show();
- returnfalse;
- }
- });
editText.setOnEditorActionListener(new OnEditorActionListener() {@Overridepublic boolean onEditorAction(TextView v, int actionId, KeyEvent event) {Toast.makeText(MainActivity.this, "text2", Toast.LENGTH_SHORT).show();return false;}});
二、修改光标颜色
在使用EditText的XML 文件中加入一个属性:
android:textCursorDrawable="@null"
android:textCursorDrawable 这个属性是用来控制光标颜色的,
"@null" 是作用是让光标颜色和text color一样
android:textCursorDrawable 的用法可以查看android sdk
public static final intTextView_textCursorDrawable
Reference to a drawable that will be drawn under the insertion cursor.
Must be a reference to another resource, in the form "@[+][package:]type:name
" or to a theme attribute in the form "?[package:][type:]name
".
This corresponds to the global attribute resource symboltextCursorDrawable
.
版权声明:本文为博主原创文章,未经博主允许不得转载。
更多相关文章
- android键盘事件
- Android(安卓)按键处理
- Android监听组合键
- android软键盘问题
- Android软键盘用法实例
- android显示和隐藏键盘
- Android输入法扩展之外接键盘中文输入
- android:windowSoftInputMode属性使用
- android:windowSoftInputMode属性使用