如何在安卓系统上做一个轮廓文字栏?[重复]

问题描述 投票:0回答:1

我正在创建一个应用程序,应该有一个文本字段,看起来像这样。enter image description here

我试着这样做 联系 和我的应用崩溃。

我现在正在尝试这样做,但我还是没有办法让它脱离我想要的方式。

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

目前的结果是正在这样。

enter image description here

如何解决这个问题?

更新。

这是com.google.android.material:material:1.1.0的一个bug。只有在1.0.0版本中才有效

https:/github.commaterial-componentsmaterial-components-androidissues776。

android android-textinputlayout
1个回答
1
投票

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

希望对你有用


0
投票

在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中修改以下内容

<EditText
android:id="@+id/edit_text"
android:background:"@drawable/edit_text_border"/>
© www.soinside.com 2019 - 2024. All rights reserved.