首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >片段中的EditText和软键盘问题

片段中的EditText和软键盘问题
EN

Stack Overflow用户
提问于 2012-12-26 16:29:34
回答 6查看 36.3K关注 0票数 29

我目前正在构建一个android应用程序,使用户能够拍摄照片并编写详细信息。这个应用程序使用的是Sherlock库。

我已经实现了一个SherlockFragment来显示图像,以及一些EditText和TextView来使用户能够键入图像的信息。但是,当其中一个EditText处于焦点位置时,所有字段都会向上推送,软键盘会弹出。

这是我的布局:

代码语言:javascript
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linear"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:background="#FFFFFF">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="200dip"
        android:layout_above="@+id/textView"
        android:layout_marginTop="20dip"
        android:layout_marginBottom="20dip"
        android:contentDescription="desc" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Title:"
        android:textStyle="bold"
        android:layout_above="@+id/editTextSimple" 
        android:layout_marginBottom="2dip"
        android:textSize="15sp"/>

     <EditText
        android:id="@+id/editTextSimple"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView1"
        android:layout_marginBottom="4dip">
        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Description:"
        android:textStyle="bold"
        android:layout_above="@+id/editTextSimple1" 
        android:layout_marginBottom="2dip"
        android:textSize="15sp"/>

    <EditText
        android:id="@+id/editTextSimple1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView2"  
        android:layout_marginBottom="12dip">
    </EditText>

    <Button android:textColor="#FF000000" 
        android:id="@+id/submitButton" 
        android:text="@string/memorySubmit" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="24dip"
        android:onClick = "submit"/>
</RelativeLayout>

据我所知,在活动中,当调用软键盘时,必须将此<activity android:windowSoftInputMode="...." >放在Android Manifest中以调整视图。然而,我们如何为片段设置它呢?

EN

回答 6

Stack Overflow用户

发布于 2013-07-11 06:16:21

在我使用多个布局和一个视图存根来创建消息传递屏幕的场景中,这对我很有效。将它放在onCreate()中希望这会有帮助。

代码语言:javascript
复制
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
票数 61
EN

Stack Overflow用户

发布于 2012-12-26 16:43:25

一个Activity的所有片段都具有与其父Activity相同的行为,但是如果您需要为不同的Fragments使用不同的键盘行为,您可以在Fragment代码中动态更改此属性,如下所示:

代码语言:javascript
复制
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.softInputMode.SOFT_INPUT_ADJUST_PAN);

希望这能有所帮助!

票数 12
EN

Stack Overflow用户

发布于 2014-04-17 18:07:07

这可以在Fragment类中用来向上移动编辑文本并滚动到结尾。

代码语言:javascript
复制
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14037915

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档