Android windowssoftinputmode=当textalignment属性中心或中心水平对齐时,Adjustpan工作不正常

Android windowssoftinputmode=当textalignment属性中心或中心水平对齐时,Adjustpan工作不正常,android,layout,android-edittext,text-alignment,adjustpan,Android,Layout,Android Edittext,Text Alignment,Adjustpan,属性android:windowSoftInputMode=“adjustPan”已在AndroidManifest.xml中指定,但它仅在第一次起作用 第二次在屏幕上显示软件键盘时,它完全隐藏了我的编辑文本 图像描述使用超链接查看图像。首次编辑文本工作正常 第二次出现问题时隐藏并重新打开键盘 注意: 1.AdjustResize安装的AdjustPan正在工作,但我需要AdjustPan,因为AdjustResize图像已调整大小 2.我也尝试过使用PreIme创建自己的Edittext(自定

属性android:windowSoftInputMode=“adjustPan”已在AndroidManifest.xml中指定,但它仅在第一次起作用

第二次在屏幕上显示软件键盘时,它完全隐藏了我的编辑文本

图像描述使用超链接查看图像。首次编辑文本工作正常 第二次出现问题时隐藏并重新打开键盘

注意:

1.AdjustResize安装的AdjustPan正在工作,但我需要AdjustPan,因为AdjustResize图像已调整大小

2.我也尝试过使用PreIme创建自己的Edittext(自定义Edittext),这对我来说也不起作用

3.如果删除文本对齐中心工作正常。但我需要文本对齐中心

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:focusableInTouchMode="true"
tools:context="com.example.raj.testapp.MainActivity">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true"
    android:id="@+id/scroll">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:descendantFocusability="beforeDescendants"
        android:focusableInTouchMode="true"
        android:orientation="vertical">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:background="#00ffffff"
            android:layout_marginTop="25dp">
            <EditText
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:background="#ffffff"
                android:alpha=".3"
                android:textColorHint="@color/black"
                android:textColor="@color/black"
                android:hint="Username"
                android:singleLine="true"
                android:textAlignment="center"
                android:fontFamily="sans-serif-light"
                android:id="@+id/register_email"
                android:textSize="20sp"/>
            <EditText
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:background="#ffffff"
                android:alpha=".3"
                android:textColorHint="@color/black"
                android:textColor="@color/black"
                android:hint="First name"
                android:singleLine="true"
                android:textSize="20sp"
                android:id="@+id/regiter_firstname"
                android:layout_marginTop="25dp"
                android:fontFamily="sans-serif-light"
                android:textAlignment="center"/>
            <EditText
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:background="#ffffff"
                android:alpha=".3"
                android:textColorHint="@color/black"
                android:textColor="@color/black"
                android:hint="Lastname"
                android:singleLine="true"
                android:textSize="20sp"
                android:id="@+id/regiter_lastname"
                android:layout_marginTop="25dp"
                android:fontFamily="sans-serif-light"
                android:textAlignment="center"/>

            <EditText
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:background="#ffffff"
                android:alpha=".3"
                android:textColorHint="@color/black"
                android:textColor="@color/black"
                android:singleLine="true"
                android:hint="Password"
                android:textSize="22sp"
                android:textAlignment="center"
                android:id="@+id/regiter_password"
                android:inputType="textPassword"
                android:layout_marginTop="25dp"
                android:fontFamily="sans-serif-light"
                />
            <EditText
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:background="#ffffff"
                android:alpha=".3"
                android:textColorHint="@color/black"
                android:textColor="@color/black"
                android:singleLine="true"
                android:hint="Confirm Password"
                android:textAlignment="center"
                android:layout_marginTop="25dp"
                android:textSize="20sp"
                android:inputType="textPassword"
                android:id="@+id/register_confirm"
                android:fontFamily="sans-serif-light"
                />

        </LinearLayout>



    </LinearLayout>

</ScrollView>
<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Next"
    android:layout_alignParentBottom="true"
    android:fontFamily="sans-serif"
    android:id="@+id/register_next"
    android:layout_marginTop="25dp"
    android:textColor="#ffffff"
    android:textAllCaps="false"
    android:background="@color/yellow"/>

</RelativeLayout>

清单文件

   <activity android:name=".MainActivity"
        android:configChanges="locale"
        android:windowSoftInputMode="stateHidden|adjustPan">

1.创建自定义editText文件[LockEditText.java]

package com.raj.app.utils;

//import statements

public class LockEditText extends android.support.v7.widget.AppCompatEditText {

public LockEditText(Context context) {
    super(context);
}

public LockEditText(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public LockEditText(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}

@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK){
        clearFocus();
    }
    return super.onKeyPreIme(keyCode, event);
}
}
2.XML文件更改com.raj.app.utils.LockEditText(文件的packagename.LockEditText) 比如像这样

    <com.raj.app.utils.LockEditText
                android:id="@+id/regiter_firstname"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_marginTop="25dp"
                android:layout_weight="1"
                android:alpha=".3"
                android:background="#ffffff"
                android:fontFamily="sans-serif-light"
                android:hint="@string/firstname"
                android:lines="1"
                android:maxLines="1"
                android:singleLine="true"
                android:textAlignment="center"
                android:textColor="@color/black"
                android:textColorHint="@color/black"
                android:textSize="20sp"/>
EditText替换为LockEditText

工作正常,当单击“完成”时会出现相同问题,因此添加以下代码

LockEditText reg_confirm=(LockEditText)findViewById(R.id.reg_confirm);

 reg_confirm.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
            if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                    case KeyEvent.KEYCODE_ENTER:
                        if(getCurrentFocus()!=null) {
                            Reg_confirm.clearFocus();
                            InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                            inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
                        }
                        break;
                    default:
                        break;
                }
            }
            return false;
        }
    });

如果您不需要喜欢大代码,只需在清单中使用adjustResize

下一步按钮隐藏确认密码编辑文本即可right@AnilDS,你是说下一步按钮隐藏edittext是的,只需给scrollview ex:50sp加上填充,然后选中第二次单击edittext该edittext被隐藏了哪个edittext被隐藏了
 EditText Reg_firstname = (EditText) findViewById(R.id.regiter_firstname);
LockEditText reg_confirm=(LockEditText)findViewById(R.id.reg_confirm);

 reg_confirm.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
            if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                    case KeyEvent.KEYCODE_ENTER:
                        if(getCurrentFocus()!=null) {
                            Reg_confirm.clearFocus();
                            InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                            inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
                        }
                        break;
                    default:
                        break;
                }
            }
            return false;
        }
    });