SoftKeyboard隐藏的EditText [英] SoftKeyboard hiding EditText

查看:115
本文介绍了SoftKeyboard隐藏的EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用一个EditText让用户搜索数据库并填充ListView控件的布局。所述的EditText是关于从屏幕的顶部的方式三分之二(定位在一个ImageView的,和随后的一些介绍文字。)

问题是,软键盘隐藏的EditText,使用户无法看到他的打字。 (我禁用了自动提示功能。)

我试过的L​​inearLayout,RelativeLayout的,填充,和不同的路线/定心,但我仍然无法得到它的工作的权利。该的EditText将被隐藏,被推向关闭屏幕的顶部,或得到压扁和歪曲。

建议???

一种可能的解决办法是,移动的EditText到屏幕的顶部。然而,这种偏离,我被赋予了平面设计。

另一种可能的解决方法是给我做的全屏幕软键盘打开(不知道怎么回事,虽然)。这将仍然隐藏的EditText,但我可以重新启用自动建议,以便用户可以看到他的打字之类的......因为他只能看到的建议的是什么他打字。

下面是我的最新尝试。请参阅introFrame。

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
 机器人:layout_width =WRAP_CONTENT
 机器人:layout_height =FILL_PARENT
 机器人:方向=垂直>

 <的LinearLayout机器人:ID =@ + ID / titleContainer
  机器人:方向=横向机器人:layout_width =FILL_PARENT
  机器人:layout_height =WRAP_CONTENT>
  < TextView的Andr​​oid版本:文本=@字符串/ title_string
   机器人:TEXTSIZE =15sp机器人:文字颜色=#FFFFFF
   机器人:TEXTSTYLE =黑体机器人:以下属性来=5DP
   机器人:layout_height =FILL_PARENT机器人:layout_width =WRAP_CONTENT/>
 < / LinearLayout中>

 <的FrameLayout
 机器人:ID =@ + ID / introFrame
 机器人:layout_width =FILL_PARENT
 机器人:layout_height =WRAP_CONTENT
 机器人:重力=center_horizo​​ntal>
 < ImageView的
  机器人:SRC =@可绘制/ main_search_image
  机器人:scaleType =中心
  机器人:layout_gravity =中心
  机器人:layout_height =WRAP_CONTENT
  机器人:layout_width =WRAP_CONTENT/>
 <的LinearLayout
  机器人:方向=垂直
  机器人:layout_width =WRAP_CONTENT
  机器人:layout_height =WRAP_CONTENT
  机器人:layout_gravity =中心
  机器人:paddingTop =140dp>
  <的LinearLayout机器人:ID =@ + ID / introSearchContainer
   机器人:方向=横向
   机器人:layout_width =WRAP_CONTENT
   机器人:layout_height =WRAP_CONTENT
   机器人:layout_gravity =center_vertical>
   <的LinearLayout
    机器人:方向=横向
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_weight =1>
    < EditText上机器人:ID =@ + ID / intro_search_box
     机器人:layout_width =WRAP_CONTENT
     机器人:layout_height =WRAP_CONTENT
     机器人:提示=请输入关键词
     机器人:imeOptions =actionGo
     机器人:inputType =为TextFilter
     机器人:MAXLINES =1/>
   < / LinearLayout中>
   <的LinearLayout
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT>
    <按钮机器人:ID =@ + ID / intro_search_button
     机器人:背景=@可绘制/ custom_button_go
     机器人:layout_width =WRAP_CONTENT
     机器人:layout_height =WRAP_CONTENT/>
    < / LinearLayout中>
  < / LinearLayout中>
  <的TextView
   机器人:文本=@字符串/ search_intro
   机器人:TEXTSIZE =15sp
   机器人:文字颜色=#FFFFFF
   机器人:layout_height =WRAP_CONTENT
   机器人:layout_width =FILL_PARENT/>
 < / LinearLayout中>
 < /的FrameLayout>

 <的LinearLayout机器人:ID =@ + ID / listContainer
  机器人:方向=垂直机器人:layout_width =FILL_PARENT
  机器人:layout_height =FILL_PARENT>
  < ListView的机器人:ID =@ + ID / ITEMLIST机器人:layout_width =WRAP_CONTENT
   机器人:layout_height =WRAP_CONTENT机器人:cacheColorHint =#00000000/>
  < TextView的Andr​​oid版本:文本=没有找到数据机器人:layout_width =FILL_PARENT
   机器人:layout_height =FILL_PARENT安卓重力=中心
   机器人:TEXTSIZE =16SP机器人:文字颜色=#FFFFFF机器人:ID =@ + ID /安卓:空/>
 < / LinearLayout中>

< / LinearLayout中>
 

解决方案

您正在寻找的是活动的<一个href="http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft"><$c$c>windowSoftInputMode属性。您可以设置这在AndroidManifest.xml文件,并给它一个值,例如:

  • adjustResize :活动的主窗口总是被调整以腾出空间给软键盘在屏幕上

  • adjustPan :活动的主窗口不能调整大小以腾出空间给软键盘相反,窗口中的内容会被自动平移,使当前的重点是。由键盘从未遮蔽和用户总是能够看到他们输入的内容。这是通常比调整大小,因为用户可能需要关闭软键盘来获得在与窗口的遮蔽部件相互作用不太理想。

adjustResize可能会为你工作,你只要包装在一个滚动型布局。它可能有负面影响,如果你有一个位图图像的背景下,因为它会被调整为好,在这种情况下,你可能需要使用adjustPan代替。

 &LT;活动机器人:windowSoftInputMode =adjustResize/&GT;
 

 &LT;活动机器人:windowSoftInputMode =adjustPan/&GT;
 

更多信息可在上面的链接。

I have a layout that uses an EditText to let users search a database and populate a ListView. The EditText is about 2/3 of the way from the top of the screen (positioned over an ImageView, and followed by some intro text.)

The problem is that the soft keyboard hides the EditText, so the user can't see what he's typing. (I disabled the auto-suggest.)

I've tried LinearLayout, RelativeLayout, paddings, and different alignments/centerings, but I still can't get it to work right. The EditText is either hidden, gets pushed off the top of the screen, or get "squished" and distorted.

Suggestions???

One possible workaround is to move the EditText to the top of the screen. However, this deviates from the graphic design that I was given.

Another possible workaround is for me to make the soft keyboard open in full screen (not sure how, though). This will still hide the EditText, but then I can re-enable the auto-suggestion so the user can see what he's typing... sort of... because he can only see the suggestions for what he's typing.

Here's my latest attempt. See "introFrame".

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="wrap_content" 
 android:layout_height="fill_parent"
 android:orientation="vertical">

 <LinearLayout android:id="@+id/titleContainer"
  android:orientation="horizontal" android:layout_width="fill_parent"
  android:layout_height="wrap_content">
  <TextView android:text="@string/title_string"
   android:textSize="15sp" android:textColor="#FFFFFF"
   android:textStyle="bold" android:paddingLeft="5dp"
   android:layout_height="fill_parent" android:layout_width="wrap_content" />
 </LinearLayout>

 <FrameLayout 
 android:id="@+id/introFrame"
 android:layout_width="fill_parent" 
 android:layout_height="wrap_content"
 android:gravity="center_horizontal" >
 <ImageView 
  android:src="@drawable/main_search_image"
  android:scaleType="center"
  android:layout_gravity="center"
  android:layout_height="wrap_content"
  android:layout_width="wrap_content"/>
 <LinearLayout
  android:orientation="vertical"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_gravity="center"
  android:paddingTop="140dp" >
  <LinearLayout android:id="@+id/introSearchContainer"
   android:orientation="horizontal" 
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_gravity="center_vertical" >
   <LinearLayout 
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1" >
    <EditText android:id="@+id/intro_search_box" 
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:hint="     Enter keyword     " 
     android:imeOptions="actionGo"   
     android:inputType="textFilter" 
     android:maxLines="1" />
   </LinearLayout>
   <LinearLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
    <Button android:id="@+id/intro_search_button" 
     android:background="@drawable/custom_button_go"
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" />
    </LinearLayout>
  </LinearLayout>
  <TextView
   android:text="@string/search_intro"
   android:textSize="15sp"
   android:textColor="#FFFFFF"
   android:layout_height="wrap_content"
   android:layout_width="fill_parent" /> 
 </LinearLayout>
 </FrameLayout>

 <LinearLayout android:id="@+id/listContainer"
  android:orientation="vertical" android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <ListView android:id="@+id/itemlist" android:layout_width="wrap_content"
   android:layout_height="wrap_content" android:cacheColorHint="#00000000" />
  <TextView android:text="No data found" android:layout_width="fill_parent"
   android:layout_height="fill_parent" android:gravity="center"
   android:textSize="16sp" android:textColor="#FFFFFF" android:id="@+id/android:empty" />
 </LinearLayout>

</LinearLayout>

解决方案

What you're looking for is the Activity's windowSoftInputMode attribute. You set this in your AndroidManifest.xml file, and give it a value such as:

  • adjustResize: "The activity's main window is always resized to make room for the soft keyboard on screen."

  • adjustPan: "The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window."

adjustResize will probably work for you, as long as you wrap the layout in a ScrollView. It may have negative effects if you have a bitmap image in the background, as it will be resized as well, in which case you may want to use adjustPan instead.

<activity android:windowSoftInputMode="adjustResize" />

or

<activity android:windowSoftInputMode="adjustPan" />

More information is available at the above link.

这篇关于SoftKeyboard隐藏的EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆