Android 为什么';“我的布局是否有足够的上移?”;调整盘“;?

Android 为什么';“我的布局是否有足够的上移?”;调整盘“;?,android,android-edittext,android-statusbar,window-soft-input-mode,adjustpan,Android,Android Edittext,Android Statusbar,Window Soft Input Mode,Adjustpan,我在我的应用程序中使用adjustPan时遇到一些问题,因为它不能正常工作。其他一些用户也遇到了这个问题,所以我认为分享这个问题()很重要 注意:我使用的是Android Studio,我使用的是“即时应用”,所以文件的位置会有点不同 在布局中使用adjustPan时,我的活动没有向上移动到软键盘上方出现EditText的位置(有关详细信息,请参见图)。无论在清单文件还是Java文件中使用,都会出现相同的结果 不仅如此,最奇怪的是,状态栏变得透明,应该位于通知图标后面的深蓝色条略微向下(详见图)

我在我的应用程序中使用
adjustPan
时遇到一些问题,因为它不能正常工作。其他一些用户也遇到了这个问题,所以我认为分享这个问题()很重要

注意:我使用的是Android Studio我使用的是“即时应用”,所以文件的位置会有点不同

在布局中使用
adjustPan
时,我的活动没有向上移动到软键盘上方出现
EditText
的位置(有关详细信息,请参见图)。无论在清单文件还是Java文件中使用,都会出现相同的结果

不仅如此,最奇怪的是,状态栏变得透明,应该位于通知图标后面的深蓝色条略微向下(详见图)

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

我仍然无法找出这个问题的原因,所以任何关于如何发现这个问题发生的原因的答案或评论都是可以的

以下是我的一些代码:

清单文件:

<activity
        android:name=".Input_Activity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustPan" />
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);
   }
}
<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" />
XML文件:

<activity
        android:name=".Input_Activity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustPan" />
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);
   }
}
<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" />


所有反馈都将不胜感激

还需要在onTouch事件中添加以下代码,以便当软键盘出现时,它将启动。例如:

 editText.setTransformationMethod(WordBreakUtil.getInstance());
 editText.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
            return false;
        }
    });

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

methodManager = (InputMethodManager) this.getSystemService(this.INPUT_METHOD_SERVICE);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
在onClick()方法中,显示键盘

methodManager.toggleSoftInputFromWindow(
    your_view_name.getApplicationWindowToken(),
    InputMethodManager.SHOW_FORCED, 0);  
如果此单词getApplicationWindowToken引发错误,请将其替换为getWindowToken

希望有帮助。

我不确定答案。但是试着换一个

<activity
    android:name=".Input_Activity"
    android:screenOrientation="portrait"
    android:windowSoftInputMode="adjustPan" />

希望这有帮助

android:windowSoftInputMode
上述属性可用于指定活动内容发生的情况

下面的图片可以更清楚地解答您的疑问

  • adjustPan:活动的主窗口未调整大小,以便为活动腾出空间 软键盘。相反,窗口的内容是 自动平移,使当前焦点不会被 键盘和用户始终可以看到他们正在键入的内容。这是 通常情况下,调整大小不如调整大小,因为用户可能需要 关闭软键盘以接触屏幕上被遮挡的部分并与之交互 窗户
  • 调整大小:活动的主窗口总是调整大小以使 屏幕上的软键盘空间
我认为没有必要添加您添加的以下代码


getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT\u INPUT\u ADJUST\u PAN)

Android Studio(我的IDE)声明:“它无法解决symbol
WordBreakUtil
”我对Android Studio有点陌生,应该怎么办:
your_view_name
,即使这不是
adjustPan
,但它总体上仍然有效。如果您能够使用
adjustPan