TextInputEditText 的 OutlinedBox 不起作用

Gan*_*ake 9 android android-edittext material-design android-textinputlayout androidx

我正在登录屏幕上工作,我想在其中使用以下视图实现材料编辑文本:

在此处输入图片说明

以下是我的代码:

<com.google.android.material.textfield.TextInputLayout
        android:layout_width="match_parent"
        style="@style/ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox"
        android:layout_height="wrap_content">

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="This is Hint"/>

    </com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)

但是 OutlinedBox 没有出现。这是它的外观:

在此处输入图片说明

请帮忙。

小智 9

styles.xml主题如下,

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
Run Code Online (Sandbox Code Playgroud)

TextInputLayout 示例:

  <com.google.android.material.textfield.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/username"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:hint="@string/user_name" />
    </com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)

希望这对你有用!


Nil*_*hod 5

用这个

style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
Run Code Online (Sandbox Code Playgroud)

相反,这个

style="@style/ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox"
Run Code Online (Sandbox Code Playgroud)

示例代码

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    android:layout_height="wrap_content">

    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="This is Hint"/>

</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)

输出 在此输入图像描述

  • 这在 Material 1.2.x 库中不起作用。相关 GitHub 问题在这里:https://github.com/material-components/material-components-android/issues/776 (2认同)