gpt4 book ai didi

Android EditText 键盘使 Fragment 消失

转载 作者:行者123 更新时间:2023-11-30 00:17:47 25 4
gpt4 key购买 nike

在我的应用程序的一个 fragment 中,我有一个编辑文本,每当我点击它时,键盘就会出现, fragment 中的所有内容都会消失,包括编辑文本。我仍然可以在键盘上打字,在我按下后退按钮后,一切都会回来,我输入的任何内容都会显示在 edittext 上,但是如何阻止一切消失?

下面是 fragment 的代码及其布局。

fragment :

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class PaymentsFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_payments, container, false);
}
}

布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"

android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<EditText
android:id="@+id/editText2"
android:layout_width="0dp"
android:layout_height="wrap_content"

android:hint="Enter Something"

app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toLeftOf="@+id/button2"

android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginRight="16dp" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="Button"

app:layout_constraintBaseline_toBaselineOf="@+id/editText2"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="@+id/editText2"

android:layout_marginLeft="0dp"
android:layout_marginRight="16dp" />

</android.support.constraint.ConstraintLayout>

最佳答案

引用:Developer documentation

android:windowSoftInputMode

The adjustment made to the activity's main window — whether it isresized smaller to make room for the soft keyboard or whether itscontents pan to make the current focus visible when part of the windowis covered by the soft keyboard.

adjustResize

The activity's main window is always resized to make room for the softkeyboard on screen.

adjustPan

The activity's main window is not resized to make room for the softkeyboard. Rather, the contents of the window are automatically pannedso that the current focus is never obscured by the keyboard and userscan always see what they are typing. This is generally less desirablethan resizing, because the user may need to close the soft keyboard toget at and interact with obscured parts of the window.

在 list 中使用这种方式:

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

关于Android EditText 键盘使 Fragment 消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46922049/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com