【问题标题】:how to make an outlined text field on android? [duplicate]如何在android上制作一个概述的文本字段? [复制]
【发布时间】:2020-10-05 03:09:47
【问题描述】:

我正在创建一个应具有如下文本字段的应用:

我试图这样做 link 并且我的应用程序崩溃了。

我现在正在尝试这样做,但我仍然没有设法将其移出我想要的方式。

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textEmailAddress"
    app:boxBackgroundMode="outline">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/editEmail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/email" />

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

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:boxBackgroundMode="outline">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/editNovoEmail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/new_email"
        android:inputType="textEmailAddress" />

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

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:boxBackgroundMode="outline"
    app:passwordToggleEnabled="true">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/editSenha"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/password"
        android:inputType="textPassword" />

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

目前的结果是这样的:

如何解决这个问题?

更新:

这是 'com.google.android.material:material:1.1.0' 上的一个错误。仅适用于 1.0.0 版

https://github.com/material-components/material-components-android/issues/776

【问题讨论】:

    标签: android android-textinputlayout material-components-android


    【解决方案1】:

    在drawable文件夹中创建一个新的xml文件edit_text_border.xml,或者任意命名,然后添加以下代码:

    <shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid
        android:color="@color/transparent"/>
    
    <corners
        android:bottomRightRadius="12dp"
        android:bottomLeftRadius="12dp"
        android:topLeftRadius="12dp"
        android:topRightRadius="12dp"/>
    <stroke
        android:color="#ffffff"
        android:width="1dp"/>
    

    并在编辑文本中更改它

    <EditText
    android:id="@+id/edit_text"
    android:background:"@drawable/edit_text_border"/>
    

    【讨论】:

      【解决方案2】:

      在您的 TextInputLayout 中添加 style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" 代替 app:boxBackgroundMode="outline"

      希望它对你有用!

      【讨论】:

        猜你喜欢
        • 2020-11-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多