RTL android:hint in TextInputLayout
Asked Answered
S

4

8

I have this XML layout:

 <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout
        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:layoutDirection="locale" 
        android:textDirection="rtl"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".app.storey.view.StoreyInsertFragment">

    <com.google.android.material.textfield.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="somthing"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginEnd="8dp"
            android:layout_marginTop="8dp"
            app:layout_constraintStart_toStartOf="parent"
            android:layout_marginStart="8dp"
            app:layout_constraintHorizontal_bias="0.0" 
            app:layout_constraintTop_toTopOf="parent">

        <com.google.android.material.textfield.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

    </com.google.android.material.textfield.TextInputLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

I want hint text show on right side but after use layoutDirection,textAlignment still show on left, how can I do this?

I see this link but not solve my problem.

Sweven answered 11/2, 2019 at 9:23 Comment(1)
Can you please post a screenshotTheologue
R
0
    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/text_input_user_name"
        style="@style/LoginInputLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginStart="@dimen/margin_editText_end_start"
        android:layout_marginTop="@dimen/margin_end_edit_text"
        android:layout_marginEnd="@dimen/margin_editText_end_start"
        android:layout_marginBottom="@dimen/margin_end_edit_text"

        app:hintAnimationEnabled="true"
        app:hintEnabled="true"
        >

        <androidx.appcompat.widget.AppCompatEditText
            android:id="@+id/edt_user_name"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center|start"
            android:gravity="center|start"
            android:textAlignment="center"
            android:hint="@string/user_name"
            android:inputType="textMultiLine"
            android:maxLength="8"
            android:padding="20dp"
            android:textColor="@color/ches_white"
            android:textColorHint="@color/ches_white"
            android:textSize="@dimen/text_size_login"/>
Rebarbative answered 11/2, 2019 at 9:52 Comment(3)
Still not working, I've already used the gravity, but there was no change in appearanceSweven
see the update. u can use EditText when using SupportRtl=true U should use start instead of an end to be rightRebarbative
tnx, it's work. i replace EditText to TextInputEditText and still working. The hint seems to have been used on the TextInputEditText :)Sweven
L
2

Use android:textAlignment="viewStart" for TextInputEditText field.

Lotti answered 15/2, 2022 at 9:6 Comment(0)
R
0
    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/text_input_user_name"
        style="@style/LoginInputLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginStart="@dimen/margin_editText_end_start"
        android:layout_marginTop="@dimen/margin_end_edit_text"
        android:layout_marginEnd="@dimen/margin_editText_end_start"
        android:layout_marginBottom="@dimen/margin_end_edit_text"

        app:hintAnimationEnabled="true"
        app:hintEnabled="true"
        >

        <androidx.appcompat.widget.AppCompatEditText
            android:id="@+id/edt_user_name"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center|start"
            android:gravity="center|start"
            android:textAlignment="center"
            android:hint="@string/user_name"
            android:inputType="textMultiLine"
            android:maxLength="8"
            android:padding="20dp"
            android:textColor="@color/ches_white"
            android:textColorHint="@color/ches_white"
            android:textSize="@dimen/text_size_login"/>
Rebarbative answered 11/2, 2019 at 9:52 Comment(3)
Still not working, I've already used the gravity, but there was no change in appearanceSweven
see the update. u can use EditText when using SupportRtl=true U should use start instead of an end to be rightRebarbative
tnx, it's work. i replace EditText to TextInputEditText and still working. The hint seems to have been used on the TextInputEditText :)Sweven
D
0
<android.support.design.widget.TextInputLayout
                    android:id="@+id/til_name"
                    style="@style/TextInputLabel2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/dimen_20dp"                       
                    android:textColorHint="@color/gray_10"
                    app:hintEnabled="true"
                    app:hintTextAppearance="@style/CustomTextAppearance2">

                    <android.support.v7.widget.AppCompatEditText
                        android:id="@+id/et_name"
                        style="@style/EditTextStyleWrap"
                        android:background="@android:color/transparent"
                        android:backgroundTint="@color/hint_line"
                        android:digits="@string/accepted_type"
                        android:gravity="end"
                        android:inputType="textPersonName"
                        android:letterSpacing="0.06"
                        android:maxLength="50"
                        android:nextFocusLeft="@+id/et_name"
                        android:nextFocusUp="@id/et_name"
                        android:textScaleX="1"
                        android:hint="name"
                        android:imeOptions="actionNext"
                        app:et_font="@{@string/font_sans_regular}"
                        tools:targetApi="lollipop" />
                </android.support.design.widget.TextInputLayout>
Disaccustom answered 11/2, 2019 at 9:57 Comment(0)
S
0

If you are using api > 17 then try setting below properties to your EditText

android:textDirection="anyRtl"
android:layoutDirection="rtl"

Also, You need to set hint to your EditText and not your TextInputLayout and set gravity to right as mentioned in other answers.

Supinator answered 11/2, 2019 at 10:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.