HugaBuga HugaBuga - 2 months ago 48
Android Question

Android EditText password, label gravitiy RTL

I spent a lot of time in attempt to resolve this issue but without success for now...

when the application runs on android with RTL language. the label(hint) of the EditText is shown at the wrong position.

Desired result
ltr layout

RTL Layout
rtl layou

XML

<?xml version="1.0" encoding="utf-8"?>

<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Login form container -->
<android.support.percent.PercentRelativeLayout
android:id="@+id/form_container"
android:layout_centerHorizontal="true"
app:layout_widthPercent="85%"
app:layout_heightPercent="30%"
app:layout_marginTopPercent="8%">

<!-- Username layout -->
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_username"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:id="@+id/input_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:inputType="textVisiblePassword|textNoSuggestions"
android:textDirection="ltr"
android:hint="@string/hint_username"/>

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

<!-- Password layout -->
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_below="@+id/input_layout_username">

<EditText
android:id="@+id/input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:textDirection="anyRtl"
android:hint="@string/hint_password"
android:inputType="textPassword" />

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

</android.support.percent.PercentRelativeLayout>

</android.support.percent.PercentRelativeLayout>


how can i fix the unnecessary margin in the RTL layout?
In addition, it would be great if it's possible to remove/hide the "visibility toggle"(eye icon) button!

Thank you!

Answer

to disable password toggle all you need is to add "passwordToggleEnabled" attribute to your TextInputLayout, for example:

<android.support.design.widget.TextInputLayout
        android:id="@+id/input_layout_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        app:passwordToggleEnabled="false">

    <EditText
        android:id="@+id/input_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:maxLines="1"
        android:textDirection="ltr"
        android:hint="@string/hint_password"
        android:inputType="textPassword" />

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