android:windowSoftInputMode ="adjustPan"不工作

标签 android keyboard

我有一个愚蠢的问题,请按照下面的图片

enter image description here

当我点击 Enter Email 时,它如下图所示,

enter image description here

现在,尽管使用了 android:windowSoftInputMode="adjustPan" android Lollipop 主题和工具栏,问题还是来了,

  1. 图片变小了。
  2. 电子邮件编辑文本应该显示在键盘上方,但实际上没有。

提出一些解决方案。

最佳答案

首先确保您在 xml 布局中提供了一个 ScrollView

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >  
...

...

</ScrollView>

然后在你的 activity 中确保你正在做这样的事情(这段代码只是为了演示在哪里使用 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);) :

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.temp);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

    final EditText time = (EditText)findViewById(R.id.timeET);
    time.setOnTouchListener(new OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            time.requestLayout();
            MyActivity.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);

            return false;
        }
    });
    final EditText date = (EditText)findViewById(R.id.dateET);
    date.setOnTouchListener(new OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            date.requestLayout();
            MyActivity.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);

            return false;
        }
    });
     }

关于android:windowSoftInputMode ="adjustPan"不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27854029/

相关文章:

java - 使困惑。如何获取返回的InputStream?

java - 如何通过AudioTrack播放大型PCM文件? (目前出现错误)

java - 如何判断按下了哪个 SHIFT 键?

java - 自定义键盘 - Android

android - 白名单不适用于人行横道

android - 如何使用 Espresso 测试 fragment

android - LayerDrawable 移除一层

android - 对话框关闭后隐藏软键盘

android - 自定义 'Keyboard' 内置在 Android 上的应用程序中

wpf - 如何在 WPF 中使用键盘快捷键?