【问题标题】:push button above keyboard键盘上方的按钮
【发布时间】:2018-10-17 23:25:27
【问题描述】:

我在片段布局中有一个 EditText 和一个按钮以及一些其他 TextView。布局的父级是约束布局,而包含它的活动是相对布局。当显示布局时,会显示键盘,但我希望将按钮推到键盘上方。我将属性 android:windowSoftInputMode="adjustResize" 赋予了包含片段布局。仍然没有帮助我!!我参考了以下链接之一Link1Link2,但答案对我没有帮助...

清单:

<activity android:name=".Otp.Otp"
            android:windowSoftInputMode="adjustResize"
            android:screenOrientation="portrait"/>

活动布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <ImageView
        android:id="@+id/otp_splash"
        android:layout_width="match_parent"
        android:scaleType="matrix"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:background="@drawable/masked_splash">
    </ImageView>
    <ImageView
        android:layout_width="@dimen/intro_logo_wdth"
        android:layout_height="@dimen/intro_logo_hght"
        android:background="@drawable/splash_logo"
        android:layout_centerHorizontal="true"
        android:id="@+id/msked_splsh_logo"
        android:layout_marginTop="50dp"/>
    <RelativeLayout
        android:id="@+id/otp_lyt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff"
        android:layout_below="@+id/msked_splsh_logo"
        android:layout_marginTop="45dp">
    </RelativeLayout>
    <ImageView
    android:layout_width="20dp"
    android:layout_height="20dp"
    android:layout_alignParentRight="true"
    android:layout_margin="8dp"
    android:background="@drawable/close"
        android:layout_alignParentEnd="true" />
</RelativeLayout>

注意: 在上面的布局中,@+id/otp_lyt是fragment被加载的id。

片段布局:

<?xml version="1.0" encoding="utf-8"?>
<layout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff">
    <TextView
        android:id="@+id/head"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/ph_verify_lbl_mrgn"
        android:text="@string/verify_your_phone_number"
        android:textColor="#bb2b67"

        android:textSize="@dimen/ph_verify_head_tsxtsze"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="4dp"
        android:text="@string/lorem_ipsum_lorem_ipsum"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/head" />
    <EditText
        android:id="@+id/phnmbr"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_marginEnd="10dp"
        android:focusable="true"
        android:fitsSystemWindows="true"
        android:focusableInTouchMode="true"
        android:background="@drawable/edt_txt_bg"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginStart="10dp"
        android:layout_marginTop="8dp"
        android:hint="@string/ph_hint"
        android:inputType="number"
        android:textSize="@dimen/ph_verify_head_tsxtsze"
        android:paddingTop="40dp"
        android:paddingLeft="10dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView" />
        <Button
        android:id="@+id/next"
        android:layout_width="match_parent"
        android:layout_height="65dp"
        android:background="@drawable/button_bg"
        android:text="@string/next"
        android:textColor="#ffffff"
        android:textSize="22sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0" />
    <ImageView
        android:id="@+id/imageView"
        android:layout_width="20dp"
        android:layout_height="25dp"
        android:elevation="2dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:background="@drawable/arrow"
        app:layout_constraintBottom_toBottomOf="@+id/next"
        app:layout_constraintEnd_toEndOf="@+id/next"
        app:layout_constraintHorizontal_bias="0.909"
        app:layout_constraintStart_toStartOf="@+id/next"
        app:layout_constraintTop_toTopOf="@+id/next"
        app:layout_constraintVertical_bias="0.571" />
</android.support.constraint.ConstraintLayout>
</layout>

截图1:

截图2:

测试: 活动布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".MainActivity">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/container"
    android:layout_marginTop="100dp"
    android:fitsSystemWindows="true">

</RelativeLayout>

</RelativeLayout>

片段布局:

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

    <EditText
        android:id="@+id/editText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="114dp"
        android:ems="10"
        android:focusable="true"
        android:fitsSystemWindows="true"
        android:inputType="textEmailAddress" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="Button" />
</RelativeLayout>

清单:

 <activity android:name=".MainActivity"
                    android:windowSoftInputMode="adjustResize|adjustPan">
                    <intent-filter>
                        <action android:name="android.intent.action.MAIN" />

                        <category android:name="android.intent.category.LAUNCHER" />
                    </intent-filter>
                </activity>

【问题讨论】:

  • 添加android:windowSoftInputMode="adjustPan"
  • 不..还是一样的兄弟
  • 从片段布局中的按钮小部件中删除 app:layout_constraintTop_toTopOf="parent" 然后检查。
  • @AIK 那不是问题
  • 尝试在你的根布局中添加android:fitsSystemWindows="true"

标签: android keyboard


【解决方案1】:

看起来你的活动是全屏的。如果是真的"adjustResize" 将无法工作。见link here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-24
    • 1970-01-01
    • 1970-01-01
    • 2013-02-25
    • 1970-01-01
    • 1970-01-01
    • 2012-10-21
    • 1970-01-01
    相关资源
    最近更新 更多