【问题标题】:Password toggle button on TextInputEditText disappears after click in Support Library 25.1.0在支持库 25.1.0 中单击后,TextInputEditText 上的密码切换按钮消失
【发布时间】:2017-05-16 23:16:44
【问题描述】:

我有一个TextInputEditTextTextInputLayoutandroid:inputType="textPassword" 一起使用app:passwordToggleEnabled="true"TextInputEditText 中显示密码切换按钮,如下图所示:


问题是一旦我按下密码切换按钮,它就会永远消失。
它在 com.android.support:design:24.2.0 版本中运行良好。

我错过了什么新东西吗?这是一个错误?

一些 gradle 项目的设置:
minSdkVersion 17
targetSdkVersion 25
编译 'com.android.support:support-v4:25.1.0'
编译'com.android.support:appcompat-v7:25.1.0'
编译 'com.android.support:cardview-v7:25.1.0'
编译 'com.android.support:design:25.1.0'

在 2 种不同的 Android 6.0 (Marshmallow) 设备上运行。

XML:

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/TextLabelGray"
    app:passwordToggleEnabled="true">

    <android.support.design.widget.TextInputEditText
        android:id="@+id/profile_field_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/perfil_field_password"
        android:inputType="textPassword"
        android:maxLines="1"
        android:maxLength="100"
        android:imeOptions="actionNext"
        android:imeActionLabel="@string/perfil_field_tipo_documento"
        android:textColor="@color/colorAccent"
        android:textSize="@dimen/perfil_text_view_text_size"
        android:paddingStart="15dp"
        android:paddingEnd="5dp"/>
</android.support.design.widget.TextInputLayout>

如果我在TextInputLayout 中将app:passwordToggleDrawable 与自定义可绘制对象一起使用,它不会消失。

相关风格:

<style name="TextLabelGray" parent="TextAppearance.AppCompat">
    <!--//hint color And Label Color in False State-->
    <item name="android:textColorHint">@color/gray_text_color</item>
    <item name="android:textColorHighlight">@color/gray_text_color</item>
    <item name="android:textColorLink">@color/gray_text_color</item>
    <item name="colorAccent">@color/gray_text_color</item>
    <item name="colorControlNormal">@color/gray_text_color</item>
    <item name="colorControlActivated">@color/gray_text_color</item>
</style>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="colorControlNormal">@color/colorControlNormal</item>

    <item name="searchViewStyle">@style/AppTheme.MySearchViewStyle</item>
</style>

【问题讨论】:

  • 我尝试了相同的代码,它正在工作。请检查一次使用的主题。
  • @AndroidGeek 我在没有android:theme="@style/TextLabelGray" 的情况下尝试过,我发现按钮并没有消失,它只是变得透明,因为我仍然可以按下它并具有隐藏/取消隐藏密码行为。尝试使用黑色背景,但仍然得到相同的结果。有什么想法吗?
  • TextInputLayout 我发现了这个:如果我在app:passwordToggleDrawableapp:passwordToggleContentDescription 中使用自定义drawable,按钮不会消失
  • 没有theme="@style/TextLabelGray" 也能正常工作。因此,为了帮助您,我们需要了解该主题。
  • 该死!这是一个错误look this linkxD

标签: android android-support-library android-inputtype android-textinputedittext


【解决方案1】:

通过以下依赖更改 gradle 文件

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-v4:25.3.1'

在 xml 文件中,为密码字段中的切换按钮添加以下行

 <android.support.design.widget.TextInputLayout
 android:id="@+id/text_input_layout_password"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_marginTop="10dp"
 app:passwordToggleEnabled="true">

          <android.support.design.widget.TextInputEditText
          android:id="@+id/text_input_edit_text_password"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:hint="Enter Password"
          android:imeActionId="@+id/login"
          android:imeActionLabel="Login"
          android:imeOptions="actionUnspecified"
          android:inputType="textPassword"
          android:maxLines="1"
          tools:text="password" />

 </android.support.design.widget.TextInputLayout>

【讨论】:

  • 您好,请回答,但我认为您需要在更多真实设备中检查它,因为这是一个错误。看看下面的link。与我在问题中发布的链接相同。
【解决方案2】:

添加

<item name="passwordToggleDrawable">@drawable/design_password_eye</item>
<item name="passwordToggleTint">@color/design_tint_password_toggle</item>
<item name="passwordToggleContentDescription">@string/password_toggle_content_description</item>

在您的 TextLabelGray 样式上,它将再次显示切换按钮。

【讨论】:

  • 如果它适用于所有版本(26、25、24...),您应该将其发布到official issue page:D
【解决方案3】:

这段代码工作正常:

  <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16sp"
            app:passwordToggleEnabled="true"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/prompt_password"
                android:imeActionId="6"
                android:inputType="textPassword"
                android:maxLines="1"
                android:fontFamily="@font/product_regular"
                android:singleLine="true" />

        </android.support.design.widget.TextInputLayout>


android {
compileSdkVersion 28
defaultConfig {
    applicationId "com"
    minSdkVersion 24
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

buildToolsVersion '28.0.2'

}

implementation 'com.android.support:exifinterface:28.0.0-rc02' 
implementation 'com.android.support:support-v4:28.0.0-rc02'
implementation 'com.android.support:support-v13:28.0.0-rc02'
implementation 'com.android.support:design:28.0.0-rc02'
implementation 'com.android.support:cardview-v7:28.0.0-rc02'
implementation 'com.android.support:recyclerview-v7:28.0.0-rc02'

【讨论】:

    猜你喜欢
    • 2017-10-14
    • 2021-09-22
    • 2023-03-15
    • 2018-12-18
    • 1970-01-01
    • 2021-12-02
    • 2021-09-12
    • 2017-04-27
    • 2017-03-03
    相关资源
    最近更新 更多