一、横屏时,弹出软键盘不全屏

不知你是否注意到,当我们手机横屏,且使用Android自带的软键盘为EditText进行文本输入时,若不进行特殊的设置,该软键盘会占用整个界面,那么,如何让键盘只占用屏幕的一部分呢?其实只需要改一个小小的属性即可!

[html] view plain copy print ?
  1. <EditText
  2. android:id="@+id/text1"
  3. android:layout_width="150dip"
  4. android:layout_height="wrap_content"
  5. 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 ?
  1. editText.setOnEditorActionListener(newOnEditorActionListener(){
  2. @Override
  3. publicbooleanonEditorAction(TextViewv,intactionId,KeyEventevent){
  4. Toast.makeText(MainActivity.this,"text2",Toast.LENGTH_SHORT).show();
  5. returnfalse;
  6. }
  7. });


二、修改光标颜色

在使用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.

Constant Value:70 (0x00000046)

如何限定Android的Text中的输入长度呢? 方法一:可以在layout xml中加上属性android:maxLength 比如: <EditText android:id="@+id/editTextShow" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hint" android:cursorVisible="false" android:lines="1" android:maxLength="16" /> 方法二:在代码中控制 editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(20)});

版权声明:本文为博主原创文章,未经博主允许不得转载。

更多相关文章

  1. android键盘事件
  2. Android(安卓)按键处理
  3. Android监听组合键
  4. android软键盘问题
  5. Android软键盘用法实例
  6. android显示和隐藏键盘
  7. Android输入法扩展之外接键盘中文输入
  8. android:windowSoftInputMode属性使用
  9. android:windowSoftInputMode属性使用

随机推荐

  1. as随笔
  2. 简单实用 layoutAnimation
  3. Android给第三方应用添加系统签名的两种
  4. adb devices 找不到设备的解决方法
  5. android 循环滚动实现
  6. Android中的HTTP通信
  7. Android下打开/关闭wifi 及 状态(5个)的
  8. Ubuntu 17.10 Android(安卓)studio 3.1
  9. QT5.2 Android(安卓)App找不到插件qmlxml
  10. android:动态申请权限(一)