为什么我的布局不能用"adjustPan"移动得足够多?

Dev*_*lte 5 android android-edittext window-soft-input-mode adjustpan android-statusbar

adjustPan在我的应用程序中使用了一些问题,因为它不能正常工作.其他一些用户也遇到过这个问题,所以我认为分享这个问题很重要(单击EditText时布局不会向上移动).

注意:我使用的是Android Studio,我正在使用"即时应用",因此文件的位置会有所不同.

当我adjustPan在布局中使用时,我的活动不会向上移动到EditText软键盘上方显示的位置(请参阅图像详细信息).无论您是在Manifest文件还是Java文件中使用它,都会出现相同的结果.

不仅如此,最奇怪的部分是状态栏变得透明,而应该在通知图标后面的深蓝色条有点下降(参见图像详细信息).

问题截图

我尝试过多次尝试解决这个问题,比如使用adjustResize,setOnTouchListener但我收到的这两个答案都没有解决这个问题.

我仍然无法弄清楚这个问题的原因,所以关于如何发现这个问题的原因的任何答案或评论也没关系.

这是我的一些代码:

清单文件:

<activity
        android:name=".Input_Activity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustPan" />
Run Code Online (Sandbox Code Playgroud)

Java文件:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.WindowManager;

public class Input_Activity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_input__activity);

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
   }
}
Run Code Online (Sandbox Code Playgroud)

XML文件:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"

android:layout_height="match_parent"
tools:context=".Input_Activity">

<EditText
    android:layout_width="214dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="8dp"
    android:inputType="number|numberDecimal"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.585"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.725" />
Run Code Online (Sandbox Code Playgroud)

所有反馈将不胜感激.

小智 3

在类级别创建一个类似 InputMethodManager methodManager 的对象。
将这些行添加到您的onCreate()方法中,

methodManager = (InputMethodManager) this.getSystemService(this.INPUT_METHOD_SERVICE);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Run Code Online (Sandbox Code Playgroud)

并在您的 onClick() 方法中显示键盘,例如

methodManager.toggleSoftInputFromWindow(
    your_view_name.getApplicationWindowToken(),
    InputMethodManager.SHOW_FORCED, 0);  
Run Code Online (Sandbox Code Playgroud)

如果这个词getApplicationWindowToken引发错误,请将其替换为getWindowToken
希望它有帮助。