简体   繁体   English

软键盘隐藏了我的edittext-android

[英]soft keyboard hides my edittext - android

I have an edittext inside my layout but when this edittext is clicked, the soft keyboard comes up and covers the entire text field. 我的布局中有一个编辑文本,但是单击此编辑文本后,软键盘会出现,并覆盖整个文本字段。 As a result, I can't see what I'm typing and it's very annoying. 结果,我看不到我在输入什么,这很烦人。 Can anyone tell me if there's a way to solve this? 谁能告诉我是否有解决方法?

EDIT: I also tried to wrap the entire layout in a scroll view. 编辑:我还试图将整个布局包装在滚动视图中。 I heard in that way I can get what I want but still nothing happens. 我以这种方式听说可以得到想要的东西,但仍然没有任何反应。 Here is the code of my layout: 这是我的布局代码:

<ScrollView android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:fillViewport="true"
 xmlns:android="http://schemas.android.com/apk/res/android">
      <RelativeLayout 
       android:id="@+id/mainLayoutMain"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:background="@drawable/background"
       android:paddingLeft="@dimen/activity_horizontal_margin"
       android:paddingRight="@dimen/activity_horizontal_margin" >

.................... Bunch of View....................
     </RelativeLayout>
</ScrollView>

What else can I do? 我还可以做些什么?

PS I tried also to set these attributes in my manifest file: PS我也尝试在清单文件中设置以下属性:

 android:windowSoftInputMode="adjustPan"

and: 和:

 android:windowSoftInputMode="adjustResize"

and even: 乃至:

 android:windowSoftInputMode="adjustPan|adjustResize"

But nothing works. 但是什么都行不通。 Everthing leads to the same result - the soft keyboard hides the edit text field. 一切都会导致相同的结果-软键盘隐藏了编辑文本字段。

One thing you can do is to make your root (parent) layout have android:layout_height="wrap_content" , this way the View will invalidate itself when soft keyboard is summoned, resize accordingly and if the EditText is aligned to bottom of this View (I recommend you use RelativeLayout as parent for this reason), it should raise aswell. 您可以做的一件事是使您的根(父)布局具有android:layout_height="wrap_content" ,这样,在召唤软键盘时, View将自身失效,并相应地调整大小,并且如果EditText对齐此View底部(出于这个原因,我建议您将RelativeLayout用作父级,它也会提高。


EDIT: 编辑:

Another thing: 另一件事:

Try setting this property into your manifest: 尝试将此属性设置到清单中:

<application ... >
    <activity
        android:windowSoftInputMode="adjustResize" ... >
        ...
    </activity>
    ...
</application>

And then change your root layout: 然后更改您的根目录布局:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:background="@drawable/background_grey"
android:fillViewport="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom" >

<!-- Your Layout content here -->

</RelativeLayout>
</ScrollView>

I dont know about any other solution, mainly due to the fact that there is no known callback, or event of sorts to handle such behaviour in code (soft keyboard spawn). 我不知道任何其他解决方案,这主要是由于没有已知的回调或某种事件来处理代码中的此类行为(软键盘生成)。

So it all lies down to layout design and properties, and how the android system handles Input events depending on that. 因此,一切都取决于布局设计和属性,以及android系统如何根据此处理Input事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM