在Android中,不想在按下EditText后(键盘出现后)隐藏EditText视图?

3
在Android应用程序中,当我点击EditText时,它会看起来像下面这样: enter image description here 我在选项卡栏上方使用了文本视图,并使用了以下代码。
 android:windowSoftInputMode="stateHidden|adjustResize|adjustPan"

在清单文件中隐藏标签,当 EditText 被按下时。但它也会像下面这样隐藏文本视图和按钮: enter image description here 我不想隐藏文本视图,我只想隐藏选项卡栏。
xml 文件
chatroom.xml:
<?xml version="1.0" encoding="utf-8"?>

<TabHost
    android:id="@+id/tabHost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1" >

            <include layout="@layout/chat_tab_list" />
        </FrameLayout>

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:windowSoftInputMode="adjustPan"
            >
        </TabWidget>
    </LinearLayout>
</TabHost>

chat_tab_list.xml :

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    android:id="@+id/chat_list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:visibility="visible" >

    <ListView
        android:id="@+id/listView"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@color/white" >
    </ListView>

    <LinearLayout
        android:id="@+id/text_entry"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom"
        android:orientation="horizontal"
        android:visibility="visible" >

        <EditText
            android:id="@+id/txt_inputText"
            android:layout_width="125dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.8"
            android:hint="@string/enter_text"
            android:inputType="text"                
            android:windowSoftInputMode="adjustResize" />

        <Button
            android:id="@+id/btn_Send"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:text="@string/send" />
    </LinearLayout>
</LinearLayout>

请指导我做这件事。

非常感谢您的帮助。


我也遇到了同样的问题,你解决了吗? - Jayesh
3个回答

2
这个问题表明你应该只需要在选项卡栏上设置android:windowSoftInputMode="adjustPan",而不是在文本输入框上设置。这样,文本输入框会正常滚动,但选项卡栏会保持不变。文本输入框应该设置为android:windowSoftInputMode="adjustResize"以便滚动。有关不同模式的详细信息,请参见this page
根据你的编辑,看起来是因为你的编辑文本框位于选项卡小部件内。你应该将编辑文本框移动到你的根LinearLayout中,并使用adjustResize软输入模式。

在 Tabbar 上是指在 TabHost 还是 TabWidget 上?谢谢。 - Ponting
@Ponting 你尝试了什么?我没有运行的模拟器。 - xdumaine
我在TabWidget中放置了android:windowSoftInputMode="adjustPan",在EditText中放置了android:windowSoftInputMode="adjustResize",在Manifest文件的activity中放置了android:windowSoftInputMode="adjustPan"。当我按下EditText时,它隐藏了TabBar,而不是像我想要的那样隐藏键盘。但是剩余的屏幕也向上移动(就像ActionBar从设备的上方移出屏幕一样)。 - Ponting
@Ponting 我更新了我的答案。你应该将EditText从选项卡小部件中移出,放到根LinearLayout中。 - xdumaine

1

请尝试这个。

在具有选项卡的活动中,将此添加到您的AndroidManifest中。

<activity
    android:name="YourActivity"
    android:windowSoftInputMode="adjustPan" >
</activity>

我尝试过了,但它没有起作用。它还隐藏了TextView和TabBar。 - Ponting
请放置您的活动布局XML文件。 - AITAALI_ABDERRAHMANE
@Ponting 请检查您是否正确地将标签添加到您的清单文件中的TabActivityClass。 - AITAALI_ABDERRAHMANE
哪个标签?我不理解。 - Ponting
不,我不能这样做。如果您愿意,我可以给您一些文件。 - Ponting
显示剩余3条评论

0
 <Activity>
   android:windowSoftInputMode="adjustPan"
 </Activity>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接