Android中圆角显示EditText,并且只能显示一行

本文介绍如何通过自定义XML资源文件实现Android应用中EditText控件的圆角背景效果,并展示了具体的XML配置及布局文件示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.res文件下drawable中创建文件edittext.xml实现圆角效果,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="@color/mytouming" />
<corners android:bottomRightRadius="5dp"
android:bottomLeftRadius="5dp" android:topLeftRadius="5dp"
android:topRightRadius="5dp" />
</shape>
圆角弧度根据需求来定,我在此处设置的事5dp

2.使用
<EditText
            android:id="@+id/et_user_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColorHint="@color/mywhite"
            android:textColor="@color/mywhite"
            android:hint="@string/login_user_name"
            android:background="@drawable/edittext"
            android:paddingLeft="15sp"
            android:paddingBottom="15sp"
            android:paddingTop="15sp"
            android:lines="1"
            android:singleLine="true"
            android:layout_marginRight="10sp"
            android:layout_marginLeft="10sp"/>
        <EditText
            android:id="@+id/et_user_pasword"
            android:layout_below="@id/et_user_name"
            android:layout_marginTop="10sp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColorHint="@color/mywhite"
            android:textColor="@color/mywhite"
            android:hint="@string/login_user_number"
            android:inputType="numberPassword"
            android:background="@drawable/edittext"
            android:lines="1"
            android:singleLine="true"
            android:paddingLeft="15sp"
            android:paddingBottom="15sp"
            android:paddingTop="15sp"
            android:layout_marginRight="10sp"
            android:layout_marginLeft="10sp"/>
android:lines="1"*****表示设置行数为一行
android:singleLine="true"*****表示只在一行上显示内容

效果如下:




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值