简体   繁体   English

如何在 TextInputLayout 的密码切换按钮上禁用涟漪效应

[英]How to disable ripple effect on password toggle button of TextInputLayout

I use TextInputLayout to show password toggle button.我使用 TextInputLayout 来显示密码切换按钮。 It is working but the ripple effect is behind the background of the EditText (I use drawable background for the EditText).它正在工作,但涟漪效果在 EditText 的背景后面(我为 EditText 使用可绘制背景)。 How can I disable the ripple effect of the password button or bring the ripple in front of the EditText background?如何禁用密码按钮的波纹效果或将波纹置于 EditText 背景前面? Here the recorded video that demonstrated the problem https://imgur.com/nYOB6Ye .这里录制的视频演示了问题https://imgur.com/nYOB6Ye

<com.google.android.material.textfield.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="25dp"
                app:hintEnabled="false"
                app:passwordToggleEnabled="true">

                <com.google.android.material.textfield.TextInputEditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/bg_edit"
                    android:hint="••••••"
                    android:inputType="textPassword"
                    android:padding="18dp" />
            </com.google.android.material.textfield.TextInputLayout>

You can achieve the same result removing the android:background="@drawable/bg_edit" in your TextInputEditText and using an OutlinedBox style :您可以在TextInputEditText中删除android:background="@drawable/bg_edit"并使用OutlinedBox 样式来获得相同的结果:

    <com.google.android.material.textfield.TextInputLayout
        android:hint="••••••"
        app:endIconMode="password_toggle"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        app:boxBackgroundColor="@color/....."
        ..>

           <com.google.android.material.textfield.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                android:padding="18dp" />

    </com.google.android.material.textfield.TextInputLayout>

Note: app:passwordToggleEnabled="true" is deprecated.注意: app:passwordToggleEnabled="true"已弃用。 Just add app:endIconMode="password_toggle" .只需添加app:endIconMode="password_toggle"

It is not brilliant solution, but it work for me.这不是出色的解决方案,但它对我有用。
materialVersion: 1.1.0材料版本:1.1.0

Koltin:科尔廷:

textInputLayout.apply {
        findViewById<View>(R.id.text_input_end_icon).setBackgroundColor(
            ResourcesCompat.getColor(resources, R.color.transparent, theme)
        )
    }

R.id.text_input_end_icon was find via Layout Inspector R.id.text_input_end_icon是通过布局检查器找到的

A simple way, create a new theme for password toggle is shown below.一种简单的方法,为密码切换创建一个新主题如下所示。 Parent theme is your main(App) theme.父主题是您的主要(应用)主题。

<style name="PasswordToggleTransparent" parent="NoActionBar">
        <item name="colorControlHighlight">#0000</item>
</style>

and apply this theme to your TextInputLayout :并将此主题应用于您的TextInputLayout

android:theme="@style/PasswordToggleTransparent"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM