android - 为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"
但是,当我使用它时,输出变成这样:
我该如何克服这个问题?
解决方案
这可能会帮助您:
<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>
结果如下:
推荐阅读
- awk - 'grep' 或 'awk' 用于从文件中提取数字数据
- version-control - Mercurial:重命名书签
- feathersjs - feathersjs 中的类是什么以及如何实现
- android - SQLite:语句/交易来源
- vba - PowerShell 异常调用“无法转换 COM 对象” - 加载类型库/DLL 时出错
- openstreetmap - 如何获取与 Overpass QL 上具有特定值的多个标签匹配的节点
- c# - 在 ASP.Net Core 应用程序中向 MassTransit Saga 发送消息
- python - pandas df[df["A"]==None] 与 df["A"].values==None 不一样
- getuikit - 在 UIKit v3 中的 div 中进行粘性工作
- python - 将 Python 包安装到 docker 映像的不同方法