首页 > 解决方案 > 为edittext添加背景会破坏布局

问题描述

我正在尝试设计一个输入文本视图。这是我使用的代码。

   <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardElevation="7dp"
        android:layout_margin="10dp"
        app:cardCornerRadius="22dp"
        android:backgroundTint="#ff7171">

        <AutoCompleteTextView
            android:id="@+id/email"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:hint="@string/prompt_email"
            android:inputType="textEmailAddress"
            android:maxLines="1"
            android:singleLine="true"/>

    </android.support.v7.widget.CardView>

我试图实现的是圆角和布局下的一点阴影。这是此代码的输出:

在此处输入图像描述

这给了我2个缺点。首先,我不能使用浮动标签。这是一个低优先级。让我烦恼的是:下划线。我正在尝试删除它。人们建议的常用方法是使用:

android:background="@null"

但是,当我使用它时,输出变成这样:

在此处输入图像描述

我该如何克服这个问题?

标签: androidxmlandroid-layout

解决方案


这可能会帮助您:

    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:contentPadding="16dp"
    android:backgroundTint="#ff7171"
    app:cardCornerRadius="16dp">

    <AutoCompleteTextView
        android:id="@+id/email"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@null"
        android:hint="@string/prompt_email"
        android:inputType="textEmailAddress"
        android:maxLines="1"
        android:singleLine="true" />
    </android.support.v7.widget.CardView>

结果如下:

这是结果


推荐阅读