`
韩悠悠
  • 浏览: 827240 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

android默认焦点设置的方法

 
阅读更多

在使用到文本框(EditText)来进行数据录入的时候,有时默认焦点会聚集到不想聚集的控件上,也就会需要对输入法进行一些控制。先看下LAYOUT定义文件中的和输入法有关的属性:

属性名说明

android:inputType指定输入法的类型,int类型,可以用|选择多个。取值可以参考:android.text.InputType类。取值包括:text, textUri, phonenumber,等。android:imeOptions指定输入法窗口中的回车键的功能,可选值为normal, actionNextactionDoneactionSearch等。部分输入法对此的支持可能不够好。

下面的LAYOUT定义文件举了一些例子说明inputTypeimeOptions的使用。<EditText android:id="@+id/textNormal"android:layout_width="fill_parent" android:layout_height="wrap_content"android:hint="Normal text"android:inputType="text"android:imeOptions="actionNext"/><EditText android:id="@+id/textInteger"android:layout_width="fill_parent" android:layout_height="wrap_content"android:hint="Integer only"android:inputType="number"android:imeOptions="actionNext"/><EditText android:id="@+id/textPhone"android:layout_width="fill_parent" android:layout_height="wrap_content"android:hint="Phone number"android:inputType="phone"android:imeOptions="actionNext"/><EditText android:id="@+id/textEmail"android:layout_width="fill_parent" android:layout_height="wrap_content"android:hint="Email"android:imeOptions="actionSend"android:inputType="textEmailAddress"/><EditText android:id="@+id/textSite"android:layout_width="fill_parent" android:layout_height="wrap_content"android:hint="Web Site"android:imeOptions="actionDone"android:inputType="textUri"/>

有时候也要对intent的默认焦点进行设置,不至于在intent跳转的时候默认焦点(光标)在EditText上,导致进入intent就打开输入法,影响界面美观。

默认焦点的顺序是:从上倒下 从左到右第一个可以输入的控件作为焦点可以使用:button.setFocusable(true);button.requestFocus();button.setFocusableInTouchMode(true);

另外,andorid布局上,可以设置这类看不到的布局控件来设置距离

<LinearLayout android:focusable="true" android:focusableInTouchMode="true" android:layout_width="0px" android:layout_height="0px"/>

在使用到文本框(EditText)来进行数据录入的时候,有时默认焦点会聚集到不想聚集的控件上,也就会需要对输入法进行一些控制。先看下LAYOUT定义文件中的和输入法有关的属性:

属性名说明

android:inputType指定输入法的类型,int类型,可以用|选择多个。取值可以参考:android.text.InputType类。取值包括:text, textUri, phonenumber,等。android:imeOptions指定输入法窗口中的回车键的功能,可选值为normal, actionNextactionDoneactionSearch等。部分输入法对此的支持可能不够好。

下面的LAYOUT定义文件举了一些例子说明inputTypeimeOptions的使用。<EditText android:id="@+id/textNormal"android:layout_width="fill_parent" android:layout_height="wrap_content"android:hint="Normal text"android:inputType="text"android:imeOptions="actionNext"/><EditText android:id="@+id/textInteger"android:layout_width="fill_parent" android:layout_height="wrap_content"android:hint="Integer only"android:inputType="number"android:imeOptions="actionNext"/><EditText android:id="@+id/textPhone"android:layout_width="fill_parent" android:layout_height="wrap_content"android:hint="Phone number"android:inputType="phone"android:imeOptions="actionNext"/><EditText android:id="@+id/textEmail"android:layout_width="fill_parent" android:layout_height="wrap_content"android:hint="Email"android:imeOptions="actionSend"android:inputType="textEmailAddress"/><EditText android:id="@+id/textSite"android:layout_width="fill_parent" android:layout_height="wrap_content"android:hint="Web Site"android:imeOptions="actionDone"android:inputType="textUri"/>

有时候也要对intent的默认焦点进行设置,不至于在intent跳转的时候默认焦点(光标)在EditText上,导致进入intent就打开输入法,影响界面美观。

默认焦点的顺序是:从上倒下 从左到右第一个可以输入的控件作为焦点可以使用:button.setFocusable(true);button.requestFocus();button.setFocusableInTouchMode(true);

另外,andorid布局上,可以设置这类看不到的布局控件来设置距离

<LinearLayout android:focusable="true" android:focusableInTouchMode="true" android:layout_width="0px" android:layout_height="0px"/>

分享到:
评论

相关推荐

    androidTV 自定义RecyclerView让当前焦点item显示在中间

    AndroidTV中自定义RecyclerView 让当前焦点item显示在中间,调用smoothToCenter(pos)就可以。

    android软键盘上移动焦点

    android自带的输入法,在软键盘上实现焦点移动,支持上下左右按键,并支持回车输入,文档以LatinIME为例

    Android取消EditText自动获取默认焦点

    本文主要介绍了Android取消EditText自动获取焦点默认行为的方法,具有很好的参考价值。下面跟着小编一起来看下吧

    Android TV 焦点框移动的实现方法

    本篇文章主要介绍了Android TV 焦点框移动的实现方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

    Android开发EditText属性.txt

     也就是说getText后可调用append方法设置文本内容。spannable 则可在给定的字符区域使用样式,参见这里1、这里2。  android:capitalize设置英文字母大写类型。此处无效果,需要弹出输入法才能看得到,参见...

    Android取消EditText自动获取焦点默认行为

    xml中也找不到相应的属性可以关闭这个默认行为 解决之道:在EditText的父级控件中找一个,设置成 代码如下: android:focusable=”true” android:focusableInTouchMode=”true” 这样,就把EditText默认的行为截断...

    Android中默认系统的声音/大小修改和配置详解

    声音管理系统用来实现声音的输入和输出、声音的控制和路由等功能,包括主和各种音源的音量调节、声音焦点控制,声音外设的检测和状态管理,声音源输入和输出的策略管理、音效的播放、音轨设置和播放、录音设置和启动...

    详细介绍Android中的视图焦点Focus的使用

    而在触摸设备上通常默认情况下只有EditText控件才具有焦点,而我们通常会遇到的一个问题就是当进入一个具有EditText的界面时键盘就会自动弹出,而且有时候可能无法消失,但需求可能是进入时不弹出键盘。而这些所有的...

    android中设置ListView的选中的Item的背景颜色

    ListView中没有默认的选择颜色,只有选择Item后的焦点颜色,鼠标点击时Item有颜色,放开鼠标后颜色也就没有了,要实现放开鼠标后选择项的背景还是有颜色的。

    Android仿泡泡窗实现下拉菜单条实例代码

    ImageButton,CheckBox等会强制获取焦点的view 此时,listview的item无法获取焦点,从而无法被点击 解决方法:给item的根布局增加以下属性 Android:descendantFocusability=blocksDescendants设置之后,Button获取...

    Android代码-KeyBoardDemo

    第一次进去的时候有时候输入框没有得到焦点,没有弹出软键盘,所以不能更好的量取软键盘高度,给了一个默认值787 软键盘默认高度。所以可以忽略不计,一旦弹出了软键盘,这个高度就被记录下来了,存在本地,以便下一...

    Google Android SDK开发范例大全(PDF高清完整版1)(4-1)

    5.12 还原手机默认桌面——重写clearWallpaper方法 5.13 置换手机背景图——Gallery与setWallpaper整合实现 5.14 撷取手机现存桌面——getWallpaper与setImageDrawable 5.15 文件资源管理器再进化——JavaI/O修改...

    Google Android SDK开发范例大全(PDF完整版4)(4-4)

    5.12 还原手机默认桌面——重写clearWallpaper方法 5.13 置换手机背景图——Gallery与setWallpaper整合实现 5.14 撷取手机现存桌面——getWallpaper与setImageDrawable 5.15 文件资源管理器再进化——JavaI/O修改...

    Google Android SDK开发范例大全(PDF高清完整版3)(4-3)

    5.12 还原手机默认桌面——重写clearWallpaper方法 5.13 置换手机背景图——Gallery与setWallpaper整合实现 5.14 撷取手机现存桌面——getWallpaper与setImageDrawable 5.15 文件资源管理器再进化——JavaI/O修改...

    Google Android SDK开发范例大全的目录

    5.12 还原手机默认桌面——重写clearWallpaper方法 5.13 置换手机背景图——Gallery与setWallpaper整合实现 5.14 撷取手机现存桌面——getWallpaper与setImageDrawable 5.15 文件资源管理器再进化——JavaI/O修改...

    Android车辆违章查询APP源代码.rar

    Android编写的实用查询APP:车辆违章查询程序源代码,根据用户输入的车辆信息(车牌号、车架号、发动机号等),可查询违章信息,根据默认查询地城市id, 初始化查询项目,可以显示隐藏行驶证图示,根据城市的配置设置...

    Google Android SDK开发范例大全(完整版附部分源码).pdf

    5.12 还原手机默认桌面——重写clearWallpaper方法 5.13 置换手机背景图——Gallery与setWallpaper整合实现 5.14 撷取手机现存桌面——getWallpaper与setImageDrawable 5.15 文件资源管理器再进化——JavaI/O修改...

Global site tag (gtag.js) - Google Analytics