【问题标题】:android:windowSoftInputMode="adjustPan" is not workingandroid:windowSoftInputMode="adjustPan" 不工作
【发布时间】:2015-01-09 04:51:08
【问题描述】:

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

当我点击输入电子邮件时,它看到如下图,

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

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

提出一些解决方案。

【问题讨论】:

    标签: android keyboard


    【解决方案1】:

    首先确保您在 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;
            }
        });
         }
    

    【讨论】:

    • 您应该只使用match_parentfill_parent 现已弃用。
    • 很高兴它帮助了你@CloyMonis
    • 第二个 OnTouchListener 应该是 date.requestLayout(); 而不是 time.requestLayout(); - i.stack.imgur.com/K6eGC.png
    • 工具栏怎么样:/不需要滚动
    【解决方案2】:

    在清单中设置configChanges 属性,如下所示

    <activity
        android:name="com.xyz.activityName"
        android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"/>
    

    无需在任何地方添加adjustPan - 既不需要在清单中,也不需要单独的视图,也不需要以编程方式。

    它永远不会让输入字段隐藏在软键盘后面。

    【讨论】:

    • 这是正确答案。不需要ScrollView 也不需要adjustPanconfigChanges 就完成了这项工作。
    • 即使布局在 ScrollView 中也无法使用全屏。可悲的是,这些答案都不起作用。
    【解决方案3】:

    确保windowFullscreen 不包含在主题中。检查values\Styles.xml 是否相同。

    如果您需要全屏,则创建另一个具有相同属性的主题(windowFullscreen 除外)并将其用于所需的活动。

    Manifest.xml 中使用adjustResize 而不是adjustPan

    Source

    【讨论】:

    • 不想丢失windowFullScreen怎么办?
    • @Senhor windowFullScreenScrollView 不合作。
    【解决方案4】:

    我还添加了“adjustNothing”。 我在 AndroidManifest.xml 中的活动是这样的:

    ...
    <activity
       android:name=".MainActivity"
       android:windowSoftInputMode="stateHidden|adjustPan|adjustNothing">
    </activity>
    ...
    

    它对我有用。请自己尝试。

    【讨论】:

      【解决方案5】:

      只需添加 android manifest.xml

      <activity
         android:name=".MainActivity"
         android:windowSoftInputMode="adjustPan|adjustNothing">
      </activity>

      【讨论】:

        猜你喜欢
        • 2016-05-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-05-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多