栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

以编程方式隐藏/显示Android软键盘

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

以编程方式隐藏/显示Android软键盘

将其添加到你的代码

android:focusableInTouchMode="true"
中将确保你的键盘在启动时不会出现在你的edittext框中。你想将此行添加到包含EditTextBox的线性布局中。你应该可以使用它来解决两个问题。我已经测试过了。简单的解决方案。

即:在你的app_list_view.xml文件中

<LinearLayout     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:orientation="vertical"     android:focusableInTouchMode="true">    <EditText         android:id="@+id/filter_edittext"    android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:hint="Search"         android:inputType="text"         android:maxLines="1"/>    <ListView         android:id="@id/android:list"         android:layout_height="fill_parent"        android:layout_weight="1.0"         android:layout_width="fill_parent"         android:focusable="true"         android:descendantFocusability="beforeDescendants"/></LinearLayout> 

------------------ 编辑:使键盘在启动时出现 -----------------------

这是为了使它们的键盘在启动时出现在用户名edittextbox上。我所做的只是在.xml文件的底部添加了一个空的Scrollview,这将第一个edittext置于焦点并弹出了键盘。我承认这是一个hack,但是我假设你只是想这样做。我已经对其进行了测试,并且效果很好。

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:paddingLeft="20dip"      android:paddingRight="20dip">    <EditText         android:id="@+id/userName"         android:singleLine="true"         android:layout_width="fill_parent"          android:layout_height="wrap_content"         android:hint="Username"          android:imeOptions="actionDone"         android:inputType="text"        android:maxLines="1"       />    <EditText         android:id="@+id/password"         android:password="true"         android:singleLine="true"          android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:hint="Password" />    <ScrollView        android:id="@+id/ScrollView01"          android:layout_height="fill_parent"android:layout_width="fill_parent">     </ScrollView></LinearLayout>

如果你正在寻找更雄辩的解决方案,那么我发现了这个可以帮助你的问题,它不像上面的解决方案那么简单,但是可能是一个更好的解决方案。我没有测试过,但显然可以。我认为这与你尝试过的解决方案相似,但对你却不起作用。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/368947.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号