键盘阻止我的编辑文本

时间:2018-03-20 04:03:05

标签: android-studio layout android-edittext

我不知道为什么键盘会阻挡我可以键入的空间。我的猜测是它是一个布局问题,因为当我启用了操作栏时它有用,但我不想要操作栏。是的,我已经尝试进入清单并将android:windowSoftInputMode =“adjustPan”(也调整大小,stateAlwaysHidden)。我查看了与此问题相关的大多数论坛。另外,要提到用户名位于应用程序的下半部分。

<EditText
    android:id="@+id/username"
    android:layout_width="250dp"
    android:layout_height="48dp"
    android:layout_marginBottom="8dp"
    android:alpha="0.65"
    android:background="@drawable/sign_in_button"
    android:ems="10"
    android:enabled="false"
    android:hint="@string/username"
    android:inputType="textPersonName"
    android:paddingLeft="20dp"
    android:paddingRight="20dp"
    android:textAlignment="textStart"
    android:textColor="@color/buttonTextColor"
    android:textColorHint="@color/buttonTextColor"
    android:visibility="invisible"
    app:layout_constraintBottom_toTopOf="@+id/createAccount"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintStart_toStartOf="parent" />

<EditText
    android:id="@+id/password"
    android:layout_width="250dp"
    android:layout_height="48dp"
    android:layout_marginBottom="9dp"
    android:alpha="0.65"
    android:background="@drawable/sign_in_button"
    android:ems="10"
    android:enabled="false"
    android:hint="@string/password"
    android:inputType="textPassword"
    android:paddingLeft="20dp"
    android:paddingRight="20dp"
    android:textAlignment="textStart"
    android:textColor="@color/buttonTextColor"
    android:textColorHint="@color/buttonTextColor"
    android:visibility="invisible"
    app:layout_constraintBottom_toTopOf="@+id/terms"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintStart_toStartOf="parent" />

<TextView
    android:id="@+id/goBack"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="16dp"
    android:layout_marginTop="16dp"
    android:textColor="@color/buttonTextColor"
    android:visibility="invisible"
    android:text="@string/goBack"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    tools:layout_editor_absoluteY="0dp" />

<TextView
    android:id="@+id/appTitle"
    android:layout_width="211dp"
    android:layout_height="wrap_content"
    android:alpha="0.65"
    android:fontFamily="cursive"
    android:text="@string/app_name"
    android:textAlignment="center"
    android:textColor="@color/appColor"
    android:textSize="36sp"
    android:textStyle="bold"
    app:layout_constraintBottom_toTopOf="@+id/slogan"
    app:layout_constraintHorizontal_bias="0.502"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent" />

<TextView
    android:id="@+id/slogan"
    android:layout_width="211dp"
    android:layout_height="30dp"
    android:text="@string/slogan"
    android:textAlignment="center"
    android:textColor="@color/buttonTextColor"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintBottom_toTopOf="@+id/signIn"
    android:layout_marginBottom="16dp"
    tools:layout_editor_absoluteY="374dp" />

<TextView
    android:id="@+id/terms"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginTop="8dp"
    android:text="@string/terms"
    android:textColor="@color/buttonTextColor"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/createAccount" />


 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_login);
    getSupportActionBar().hide();

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

将此属性放入您的活动

<activity
    android:windowSoftInputMode="adjustPan"
/>

如果没有工作,请在setContentView之后将其放在onCreate()方法中:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);