Android进入一个新页面,EditText失去焦点并禁止弹出键盘
android在进入一个新页面后,edittext会自动获取焦点并弹出软键盘,这样并不符合用户操作习惯。
在其父控件下,添加如下的属性,就可以完美解决,使其进入页面后不主动获取焦点,并且不弹出软键盘:
android:focusable="true"
android:focusableInTouchMode="true"
代码如下:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
<!--表单-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical"> <View
android:layout_width="match_parent"
android:layout_height="14dp"
android:background="@color/stroke_color" /> <View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/stroke_color" /> <TextView
android:id="@+id/tv_title_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="18dp"
android:layout_marginLeft="21dp"
android:layout_marginTop="18dp"
android:text="@string/title_coming_menu"
android:textColor="@color/font_dark_gray"
android:textSize="18sp" /> <View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/stroke_color" /> <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"> <RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"> <TextView
android:id="@+id/FromMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginLeft="21dp"
android:layout_marginTop="21dp"
android:text="@string/title_coming_unit"
android:textColor="@color/font_gray"
android:textSize="16sp" /> <TextView
android:id="@+id/txtFromMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/FromMessage"
android:layout_toRightOf="@+id/FromMessage"
android:textColor="@color/activity_dark3"
android:textSize="16sp" />
</RelativeLayout> <TextView
android:layout_width="1px"
android:layout_height="match_parent"
android:layout_marginTop="13dp"
android:background="@color/plan_detail_line" /> <RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"> <TextView
android:id="@+id/FromMessageNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginLeft="17dp"
android:layout_marginTop="21dp"
android:text="@string/title_coming_number"
android:textColor="@color/font_gray"
android:textSize="16sp" /> <TextView
android:id="@+id/txtFromMessageNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/FromMessageNo"
android:layout_toRightOf="@id/FromMessageNo"
android:textColor="@color/activity_dark3"
android:textSize="16sp" />
</RelativeLayout>
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"> <RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_weight="1"> <TextView
android:id="@+id/Signer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginLeft="21dp"
android:text="@string/title_coming_signer"
android:textColor="@color/font_gray"
android:textSize="16sp" /> <TextView
android:id="@+id/txtSigner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/Signer"
android:layout_toRightOf="@+id/Signer"
android:textColor="@color/activity_dark3"
android:textSize="16sp" />
</RelativeLayout> <TextView
android:layout_width="1px"
android:layout_height="match_parent"
android:background="@color/plan_detail_line" /> <RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_weight="1"> <TextView
android:id="@+id/FilePriorities"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginLeft="17dp"
android:text="@string/title_coming_priority"
android:textColor="@color/font_gray"
android:textSize="16sp" /> <TextView
android:id="@+id/txtFilePriorities"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/FilePriorities"
android:layout_toRightOf="@+id/FilePriorities"
android:textColor="@color/activity_dark3"
android:textSize="16sp" />
</RelativeLayout>
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"> <RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"> <TextView
android:id="@+id/ReceiptNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="21dp"
android:layout_marginLeft="21dp"
android:text="@string/title_coming_identifier"
android:textColor="@color/font_gray"
android:textSize="16sp" /> <TextView
android:id="@+id/txtReceiptNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/ReceiptNumber"
android:layout_toRightOf="@+id/ReceiptNumber"
android:textColor="@color/activity_dark3"
android:textSize="16sp" />
</RelativeLayout> <TextView
android:layout_width="1px"
android:layout_height="match_parent"
android:layout_marginBottom="13dp"
android:background="@color/plan_detail_line" /> <RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout> <View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/stroke_color" /> <View
android:layout_width="match_parent"
android:layout_height="14dp"
android:background="@color/stroke_color" /> <View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/stroke_color" />
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical"> <View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/stroke_color" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="18dp"
android:layout_marginLeft="21dp"
android:layout_marginTop="18dp"
android:text="@string/title_signfor_branch"
android:textColor="@color/font_dark_gray"
android:textSize="18sp" /> <View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/stroke_color" /> <RelativeLayout
android:id="@+id/rlFileType"
android:layout_width="match_parent"
android:layout_height="wrap_content"> <TextView
android:id="@+id/txtFileType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="18dp"
android:layout_marginLeft="21dp"
android:layout_marginTop="24dp"
android:text="@string/title_file_type"
android:textColor="@color/font_gray"
android:textSize="16sp" /> <RadioGroup
android:id="@+id/rgFileType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="19dp"
android:layout_toRightOf="@+id/txtFileType"
android:checkedButton="@+id/rbDoArticle"
android:orientation="horizontal"> <RadioButton
android:id="@+id/rbDoArticle"
style="@style/FileTypeRadioButtonNew"
android:text="@string/title_fileType_branch" /> <RadioButton
android:id="@+id/rbReadPiece"
style="@style/FileTypeRadioButtonNew"
android:layout_marginLeft="20dp"
android:text="@string/title_fileType_read_piece" /> <RadioButton
android:id="@+id/rbTelegram"
style="@style/FileTypeRadioButtonNew"
android:layout_marginLeft="20dp"
android:text="@string/title_fileType_telegram" /> <RadioButton
android:id="@+id/rbElse"
style="@style/FileTypeRadioButtonNew"
android:layout_marginLeft="20dp"
android:text="@string/title_fileType_another" />
</RadioGroup>
</RelativeLayout> <RelativeLayout
android:id="@+id/rlPoints"
android:layout_width="match_parent"
android:layout_height="wrap_content"> <TextView
android:id="@+id/Points"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="21dp"
android:layout_marginTop="18dp"
android:text="@string/title_branch_department"
android:textColor="@color/font_gray"
android:textSize="16sp" /> <TextView
android:id="@+id/txtPoints"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_toRightOf="@+id/Points"
android:background="@drawable/shape_tv_signfor_pointfor"
android:paddingBottom="3dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="3dp"
android:text="@string/content_pointfor"
android:textColor="@color/flowmsg_doing" />
</RelativeLayout> <RelativeLayout
android:id="@+id/rlOpinion"
android:layout_width="match_parent"
android:layout_height="wrap_content"> <TextView
android:id="@+id/Opinion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="21dp"
android:layout_marginTop="18dp"
android:text="@string/title_branch_advice"
android:textColor="@color/font_gray"
android:textSize="16sp" /> <EditText
android:id="@+id/txtOpinion"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginRight="20dp"
android:layout_marginTop="19dp"
android:layout_toRightOf="@+id/Opinion"
android:background="@drawable/shape_et_bg"
android:gravity="top"
android:hint="@string/hint_write_branch_advice"
android:padding="9dp"
android:textColor="@color/tab_text"
android:textSize="14sp" />
</RelativeLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="40dp"
android:layout_marginTop="40dp"
android:gravity="center"> <Button
android:id="@+id/tv_sign_for"
android:layout_width="250dp"
android:layout_height="50dp"
android:background="@drawable/selector_btn"
android:text="@string/btn_signfor_branch"
android:textAppearance="@style/common_text_size"
android:textColor="@color/white" /> <Button
android:id="@+id/tv_retreat"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_marginLeft="40dp"
android:background="@drawable/selector_btn_3"
android:text="@string/btn_retreat"
android:textAppearance="@style/common_text_size"
android:textColor="@color/flowmsg_doing" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
不一定只加在父级布局中,如果没有效果,可以试试更高级的父级布局中,就像示例代码中展示的一样,写在scrollview下面的布局之中。
Android进入一个新页面,EditText失去焦点并禁止弹出键盘的更多相关文章
- 《笔记篇》非JS方法跳转到一个新页面,主要防止客户端禁止浏览器JS以后的跳转异常
用非JS方法打开一个新页面,主要防止客户端禁止浏览器JS以后的跳转失效 <meta http-equiv="refresh" content="0; url=htt ...
- Android中使EditText失去焦点,edittext禁止弹出键盘[转]
转自http://www.cnblogs.com/yejiurui/archive/2013/01/02/2841945.html 在我们的应用中,有时候一进入一个页面, EditText默认就会自动 ...
- :input获得焦点时被弹出键盘挡住解决办法
这个是移动端非常常见的bug了,这里说下综合的解决办法,因为有时候你的办法就是会失效.. 上代码 /*input框调起输入法盖住输入问题*/$('input[type="text" ...
- IPhone手机页面中点击文本输入框,弹出键盘,网页会放大,如何解决
在head标签中加入以上meta声明.具体属性可以谷歌/百度. <meta name="viewport" content="width=device-width, ...
- 直接提交一个form表单后台返回一个新页面通过target属性可以放到iframe当中
问题描述: 我想提交一个form表单后台直接返回一个新页面,但是当前页面还不想被替换掉: 解决方案: 在页面中添加一个iframe将form表单的target属性设置为iframe的id这样的话返回的 ...
- selenium获取新页面标签页(只弹出一个新页面的切换)
selenium获取新页面标签页(只弹出一个新页面的切换) windows = driver.current_window_handle #定位当前页面句柄 all_handles = driver. ...
- PHP——0128练习相关2——js点击button按钮跳转到另一个新页面
js点击button按钮跳转到另一个新页面 投稿:whsnow 字体:[增加 减小] 类型:转载 时间:2014-10-10我要评论 点击按钮怎么跳转到另外一个页面呢?点击图片要跳转到新的页面时,怎么 ...
- android 创建一个新的每次project什么时候 请问自己主动 参加 V7依赖?
android 创建一个新的每次project什么时候 请问自己主动 参加 V7依赖? 分析原因: 主要是由于.我之前的 SDK 的版本号 更新的有点高了.低版本号是不会有这样的问题g的,新版本号中g ...
- JS解析Json 数据并跳转到一个新页面,取消A 标签跳转
JS解析Json 数据并跳转到一个新页面,代码如下 $.getJSON("http://api.cn.abb.com/common/api/staff/employee/" + o ...
随机推荐
- 单例模式(C#实现)
这是这段时间学习设计模式的时候的源代码. 单例(单件)模式的五种实现. 通过一个计数器的例子调用验证一下. 把下面的代码直接拷进vs下,运行就可以了.(控制台应用程序) 以后把剩余的设计模式有空儿就粘 ...
- laravel5.5更新到laravel5.7
为什么要更新呢?因为项目用的第三方后台扩展包,有很些bug,不够完美.想要一个漂亮的后台,那个后台只支持5.7. 然后,我就开始更新框架了. 修改后:"php": "&g ...
- stack、queue实现
//SGI STL以deque作为缺省情况下的stack底部结构,stack没有迭代器,不提供遍历功能 //queue的实现类似stack,也是以deque作为缺省底层结构 template < ...
- HDU 4849 Wow! Such City!陕西邀请赛C(最短路)
HDU 4849 Wow! Such City! 题目链接 题意:依照题目中的公式构造出临接矩阵后.求出1到2 - n最短路%M的最小值 思路:就依据题目中方法构造矩阵,然后写一个dijkstra,利 ...
- wpf slider进度条的样式模板,带有进度颜色显示
效果图: 仅仅需在前台加上这段代码就可以: <UserControl.Resources> <!--笔刷--> <LinearGradientBrush x:Key=&q ...
- HDU 5305 Friends(简单DFS)
Friends Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Su ...
- com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$Mis
为什么会出现这个错误? 我使用了Maven配置Struts,所以改动Struts配置文件的默认路径,例如以下: <!-- 配置struts --> <filter> <f ...
- linux下非root用户怎样改动root权限的文件
在linux下会出现把一些配置文件參数配错.rootpassword忘记等导致系统无法启动或进入root的窘迫境界.本文以redhat enterprise linux server ...
- PhoneGap:JS跨域请求
PhoneGap开发,理论上好处多多.但因为javascript是其中的主角,并且是直接存放于手机,跟服务器数据交互,就会有一个跨域访问的问题. 当然,这个问题肯定有解决方案,不然的话,这种利用Pho ...
- Codeforces Round #329 (Div. 2)B. Anton and Lines 贪心
B. Anton and Lines The teacher gave Anton a large geometry homework, but he didn't do it (as usual ...