繁体   English   中英

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

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

我使用 TextInputLayout 来显示密码切换按钮。 它正在工作,但涟漪效果在 EditText 的背景后面(我为 EditText 使用可绘制背景)。 如何禁用密码按钮的波纹效果或将波纹置于 EditText 背景前面? 这里录制的视频演示了问题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>

您可以在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>

注意: app:passwordToggleEnabled="true"已弃用。 只需添加app:endIconMode="password_toggle"

这不是出色的解决方案,但它对我有用。
材料版本:1.1.0

科尔廷:

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

R.id.text_input_end_icon是通过布局检查器找到的

一种简单的方法,为密码切换创建一个新主题如下所示。 父主题是您的主要(应用)主题。

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

并将此主题应用于您的TextInputLayout

android:theme="@style/PasswordToggleTransparent"

暂无
暂无

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

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