Change PasswordToggle Gravity to the left (for RTL language)

旧时模样 提交于 2019-12-10 10:16:37

问题


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:

But i want something like this:

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

android:supportsRtl="false"

回答1:


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);


来源:https://stackoverflow.com/questions/43968840/change-passwordtoggle-gravity-to-the-left-for-rtl-language

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!