簡體   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