Gaël
Gaël

Reputation: 25

TextInputLayout floating label gravity

I'm having some troubles with the TextInputLayout from the design support library on Android 4.1.

So, I have a simple layout with two TextInputLayout. I would like to have the hint on right because the text is in arabic.

I managed to put the hint on the right by using gravity="right". But I'm noticing a strange behaviour of the floating label when the EditText is focused.

The Floating label still stick to the left of the screen.

How can I have both the hint and the floating label on right ?

Here is my layout :

<LinearLayout     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:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.aurelien.testblablabla.MainActivity">

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="end"
            android:hint="جزر"/>
    </android.support.design.widget.TextInputLayout>
    <android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="end"
            android:hint="تفاحة"/>
    </android.support.design.widget.TextInputLayout>
</LinearLayout>

And here is the result:

enter image description here

I'm using com.android.support:design:23.1.1

Thanks

Upvotes: 1

Views: 2412

Answers (3)

Samer Shaat
Samer Shaat

Reputation: 1

use layout Direction it solve your problem

 <android.support.design.widget.TextInputLayout
        android:id="@+id/img_edit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:errorEnabled="true"
        app:helperText="URL"
        android:layoutDirection="ltr"
        app:helperTextEnabled="true">

Upvotes: 0

Lior Prigal
Lior Prigal

Reputation: 1

It is possible.

use android:gravity="right" on the EditText

I did it like this:

<android.support.design.widget.TextInputLayout
        android:id="@+id/ti_cvv"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:gravity="right"
        android:layout_marginRight="8dp"
        android:layout_marginTop="16dp"
        app:layout_constraintLeft_toLeftOf="@id/guideline"
        app:layout_constraintRight_toRightOf="@+id/guideline_center"
        app:layout_constraintTop_toBottomOf="@+id/ti_credit_card_number"
        >

        <android.support.design.widget.TextInputEditText
            android:id="@+id/et_cvv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:gravity="right"
            android:hint="@string/cvv"
            android:textColor="@color/white"
            tools:text="XXXX"/>

    </android.support.design.widget.TextInputLayout>

Upvotes: 0

Kristiyan Varbanov
Kristiyan Varbanov

Reputation: 2509

I believe that you can't customize the label position TextInputLayout. Either way if you using TranslationY even this is not the suitable solution for changing the floating label postion because it will translate any view.

Upvotes: 0

Related Questions