在页面的开发过程中,我们可能会遇到这样的情况,打开某个页面(Activity)时,如果该页面中有EditText组建,则会自动弹出软键盘(因为该EditText自动获取焦点了),这样很容易影响用户体验; 所以,在设计页面时,我们有必要首先手动让该EditText失去焦点,这样,才可以避免软键盘弹出。

如何实现呢? 其实很简单,我们只需要让EditText的父容器获取焦点就可以了。

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:paddingBottom="2dp"
android:paddingTop="2dp" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="用户名:"
android:textColor="#4a4a4a"
android:textSize="14sp" /> <EditText
android:id="@+id/total_price_edit"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:gravity="right|center_vertical"
android:inputType="numberDecimal"
android:paddingRight="6dp"
android:textColor="#ff8400"
android:textSize="23sp" >
</EditText>
</RelativeLayout>

注:

上述代码中,我们手动设置EditText的父容器RelativeLayout获取焦点:

android:focusable="true"

android:focusableInTouchMode="true"

通过这种方式,便可以很轻松的避免软键盘的弹出了

Android 隐藏EditText的焦点的更多相关文章

  1. Android - 隐藏EditText弹出的软键盘输入(SoftInput)

    隐藏EditText弹出的软键盘输入(SoftInput) 本文地址: http://blog.csdn.net/caroline_wendy 保持界面的整洁, 能够选择在进入界面时, 隐藏EditT ...

  2. android隐藏EditText光标

    在android中如果有EditText,那么在载入时,光标会默认显示在第一个EditText框中,如果不想显示光标,且也不想把该光标移动到下一个EditText框,最简单的方法是在该 EditTex ...

  3. 键盘--android 隐藏系统键盘

    . -----------------------------------------已验证----------------------------------- public static void ...

  4. android 隐藏系统键盘

    -----------------------------------------已验证----------------------------------- public static void c ...

  5. Android中Edittext的属性

    //此为转载别人的,挺不错的 1.EditText输入的文字为密码形式的设置 (1)通过.xml里设置: 把该EditText设为:android:password="true"  ...

  6. Android中EditText显示明文与密文的两种方式

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 记录输入框显示.隐藏密码的简单布局以及实现方式. 效果图    代码分析 方式一 /**方式一:*/ private void sh ...

  7. Android 自定义EditText实现类iOS风格搜索框

    最近在项目中有使用到搜索框的地方,由于其样式要求与iOS的UISearchBar的风格一致.默认情况下,搜索图标和文字是居中的,在获取焦点的时候,图标和文字左移.但是在Android是并没有这样的控件 ...

  8. Android 禁止Edittext弹出系统软键盘 的几种方法

    第一种方法:在XML文件下添加: android:focusable="true" android:focusableInTouchMode="true" 第二 ...

  9. Android开发 EditText的开发记录

    设置显示内容与隐藏内容 if (isChecked){ editPassword.setTransformationMethod(HideReturnsTransformationMethod.get ...

随机推荐

  1. web前端学习(四)JavaScript学习笔记部分(5)-- 事件流详解

    1.JS事件详解-事件流 1.1.事件流 1.事件流: 描述的是在页面中接受事件的顺序 2.事件冒泡: 由最具体的元素接收,然后逐级上传播至最不具体的节点(文档) 3.事件捕获: 最不具体的节点先接收 ...

  2. Android消息机制使用注意事项,防止泄漏

    在Android的线程通信当中,使用频率最多的就是Android的消息处理机制(Handler.send().View.post().Asynctask.excute()等等都使用到了消息处理机制). ...

  3. 解决IE6、IE7、Firefox兼容最简单的CSS Hack

    写三句代码来控制一个属性,区别Firefox,IE7,IE6: background:orange; *background:green !important; *background:blue;   ...

  4. 关于父组件通过v-on接收子组件多个参数的一点研究

    写组件的时候遇到一个需求,我需要在子组件向父组件传递信息 this.$emit('myEvent', 信息1, 信息2) 在父组件使用v-on来接收 <my-component @myEvent ...

  5. mysql各个引擎区别

    1.如果你有一个 MyISAM 数据表包含着 FULLTEXT 或 SPATIAL 索引,你将不能把它转换为使用 另一种引擎,因为只有 MyISAM 支持这两种索引. 2. 如果你有一个数据表包含着一 ...

  6. 云服务器 ECS Linux Web 环境配置站点的方法

    摘自:https://help.aliyun.com/knowledge_detail/41100.html ECS Linux 系统一键安装 Web 环境<专业版>下 Tomcat 添加 ...

  7. ThinkPHP5.0中报错could not find driver的解决方式

    这个报错是我的tp5项目转移到另外的服务器中发生的错误, 其中报错信息中还包含这pdo等字眼 解决方法:在php.ini中开启php_pdp_mysql.dll

  8. BigDecimal创建初始化值类型对比

    当初始化String类型和double类型,入参值相同,对比输出值 BigDecimal bigDecimalStr = new BigDecimal("0.1"); BigDec ...

  9. PHPCMS快速建站系列之phpcms v9 模板标签说明整理

    [摘要]本文介绍phpcms v9中模板标签使用说明. {template "content","header"} 调用根目录下phpcms\template\ ...

  10. 【To Read】LeetCode | Jump Game II(转载)

    题目: Given an array of non-negative integers, you are initially positioned at the first index of the ...