1

There is an issue with constraint layout and soft keyboard in my application. I changed layout direction for whole app from style by adding <item name="android:layoutDirection">rtl</item> inside the default app theme. But this affects the direction of constraint layout when soft keyboard shows. see the pictures below.

before touching edit text:

enter image description here

after touching edit text:

enter image description here

I have tried:

  1. different combination of android:windowSoftInputMode="adjustPan|stateAlwaysHidden|stateHidden" in manifest.

  2. adding android:layoutDirection="ltr" to constraint layout parameter.

<androidx.cardview.widget.CardView 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="180dp"
    android:layout_alignParentBottom="true"
    android:layout_gravity="center_horizontal"
    android:layout_marginLeft="@dimen/recycle_margin"
    android:layout_marginTop="30dp"
    android:layout_marginRight="@dimen/recycle_margin"
    android:layout_marginBottom="@dimen/recycle_margin_half"
    android:foreground="?attr/selectableItemBackground"
    app:cardCornerRadius="@dimen/card_border"
    app:cardElevation="@dimen/card_elevation">
    <!--TODO: maximum width-->

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="10dp">

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/dl_header"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.2" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:scaleType="fitStart"
            app:layout_constraintBottom_toTopOf="@+id/dl_header"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/shetab" />

        <TextView
            android:id="@+id/card_pan_mask"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="@font/credc"
            android:text="6104 33** **** 7928"
            android:textDirection="ltr"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/card_exp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="@font/credc"
            android:text="61/22"
            android:textDirection="ltr"
            app:layout_constraintBottom_toTopOf="@id/card_name"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@id/card_pan_mask" />

        <TextView
            android:id="@+id/cvv2_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="@font/credc"
            android:text="CVV:"
            android:textDirection="ltr"
            app:layout_constraintBottom_toTopOf="@id/card_name"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/card_pan_mask" />

        <EditText
            android:id="@+id/card_cvv2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="@font/credc"
            android:background="@drawable/date_shape"
            android:text="6103"
            android:textDirection="ltr"
            android:paddingHorizontal="10dp"
            android:paddingVertical="5dp"
            app:layout_constraintBottom_toTopOf="@id/card_name"
            app:layout_constraintStart_toEndOf="@+id/cvv2_text"
            app:layout_constraintTop_toBottomOf="@id/card_pan_mask" />

        <EditText
            android:id="@+id/card_name"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:background="@drawable/date_shape"
            android:layoutDirection="rtl"
            android:maxLines="1"
            android:paddingHorizontal="10dp"
            android:paddingVertical="5dp"
            android:text="متن تست"
            android:textDirection="rtl"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent" />


    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
H00man
  • 375
  • 1
  • 7
  • 21

0 Answers0