具有材料轮廓框的boxStroke不起作用

时间:2020-10-29 17:20:04

标签: android material-design material-components-android outline

我正在尝试使用Material Design为Android设计一个非常简单的UI。

登录界面的想法是2个轮廓框,一个用于电子邮件,一个用于密码。密码框应包含一个尾随图标,如果按该图标,它将显示您的密码。这里没有代码问题,所有的事情都应该由Material.io

实现

所以我面临的问题是关于boxStroke。

运行该应用程序时,您可以清楚地看到boxStroke(但是在密码文本框上,使尾随图标消失了轮廓)。

![notFocused]

将焦点放在其中一个文本框后,它将显示如下:

Focused

您会发现盒子的轮廓完全消失了。如果您添加至少一个字符,它将返回:

notEmptyBox

两个textBoxes的代码都在这里,与Material.io主页中的代码几乎相同,我将在本文结尾处发布材料Wiki的链接:

电子邮件文本框:

    <com.google.android.material.textfield.TextInputLayout
    android:id="@+id/login_email_layout"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:hint="@string/login_hint_email"
    app:boxStrokeWidthFocused="3dp"
    app:errorEnabled="true"
    app:layout_constraintBottom_toTopOf="@+id/login_password_layout"
    app:layout_constraintEnd_toEndOf="@+id/imageView"
    app:layout_constraintStart_toStartOf="@+id/imageView"
    app:layout_constraintTop_toBottomOf="@+id/imageView"
    app:shapeAppearanceOverlay="@style/ShapeAppearance.MaterialComponents.SmallComponent">

    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/textColor" />

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

密码文本框:

    <com.google.android.material.textfield.TextInputLayout
    android:id="@+id/login_password_layout"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:hint="@string/login_hint_password"
    app:endIconMode="password_toggle"
    app:errorEnabled="true"
    app:layout_constraintBottom_toTopOf="@+id/login_forgot_password"
    app:layout_constraintEnd_toEndOf="@+id/login_email_layout"
    app:layout_constraintStart_toStartOf="@+id/login_email_layout"
    app:layout_constraintTop_toBottomOf="@+id/login_email_layout">

    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:textColor="@color/textColor"
        android:visibility="visible" />

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

我不知道为什么尾随图标使轮廓消失,即使空白,我也无法使轮廓聚焦。因此,欢迎您提供任何帮助。

谢谢。

PD:当前使用的是1.2.1素材版本,尝试切换到1.3.1-alpha03版本,但不会显示任何文本框。

Material Outlined Box

编辑: 添加graddle:app,以防它给您更多信息:

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
implementation platform('com.google.firebase:firebase-bom:25.12.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.android.material:material:1.2.1'
implementation 'com.google.gms:google-services:4.3.4'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.19'
implementation 'com.google.android.gms:play-services-auth:18.1.0'
implementation "androidx.navigation:navigation-fragment:2.3.1"
implementation "androidx.navigation:navigation-ui:2.3.1"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

1 个答案:

答案 0 :(得分:1)

刚刚找到答案:

几天后,我又回到了这个问题上(这只是一个美学问题,所以我继续编程其他东西,例如圣火基础的东西)。

所以问题是在

styles.xml
上我声明并初始化了@ color / background。并且用于textEdit的Material Design API将此颜色用于轮廓。

因此解决方案是简单地删除@ color / background。我本可以在xml文件android:background = @ null上进行设置,但是必须在每个使用textEdit的xml文件上进行设置。

希望这可以帮助某人,对不起您如此愚蠢。