Hamid Goodarzi
Hamid Goodarzi

Reputation: 1394

Change PasswordToggle Gravity to the left (for RTL language)

I use TextInputLayout to get password from user like this:

<android.support.design.widget.TextInputLayout
                android:id="@+id/RegisterPassInput"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                app:passwordToggleEnabled="true"
                android:layout_marginRight="16dp"
                android:layout_toStartOf="@+id/RegisterPassImg">

                <EditText
                    android:id="@+id/RegisterPassET"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="right"
                    android:hint="@string/Password"
                    android:inputType="textPassword"
                    android:maxLength="40" />
            </android.support.design.widget.TextInputLayout>

and the result is:

enter image description here

But i want something like this:

enter image description here

How can i set passwordToggle gravity align left of the editText.
For lots of reasons I disabled rtl support in manifest

android:supportsRtl="false"

Upvotes: 3

Views: 1006

Answers (1)

Barak
Barak

Reputation: 1429

In your TextInputLayout, add this argument:

android:layoutDirection="rtl"

Edit: for API < 17 (Using android.support.v4.view.ViewCompat):

TextInputLayout inputLayout = (TextInputLayout) findViewById(R.id.RegisterPassInput); 
ViewCompat.setLayoutDirection(inputLayout, ViewCompat.LAYOUT_DIRECTION_RTL);

Upvotes: 7

Related Questions