本文介绍了将PasswordToggle Gravity更改为左侧(对于RTL语言)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用TextInputLayout这样从用户获取密码:

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>

结果是:

但是我想要这样的东西:

But i want something like this:

如何设置passwordToggle重力在editText的左侧对齐.
由于多种原因,我在清单

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

android:supportsRtl="false"

推荐答案

在您的TextInputLayout中,添加以下参数:

In your TextInputLayout, add this argument:

android:layoutDirection="rtl"

修改:对于API< 17(使用android.support.v4.view.ViewCompat):

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

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

这篇关于将PasswordToggle Gravity更改为左侧(对于RTL语言)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 04:05