EditText在应用中经常遇到的问题(改背景、缩进、去下划线、去焦点)--以绑定手机界面为例介绍

目录

改背景

缩进

去下划线

去焦点


绑定手机界面整体样式:

改背景

 bindingphone_btn_color.xml(可以写自己需要的样式)

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="20dp"/>
    <solid android:color="#F2F2F4"/>
</shape>

layout里面的xml文件内容:android:background="@drawable/bindingphone_btn_color"

<EditText
        android:id="@+id/editText3"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginStart="24dp"
        android:layout_marginTop="64dp"
        android:layout_marginEnd="24dp"
        android:background="@drawable/bindingphone_btn_color"
        android:hint="请输入手机号码"
        android:textSize="16sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView69" />

缩进

有时候当我们改变了后面的背景,会发现光标闪烁在很左边,影响美观,具体现象可见下图

 解决方案:

在调用的背景drawable里xml文件中添加<padding android:left="xxdp"/>该语句即可解决。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <corners android:radius="20dp"/>
    <solid android:color="#F2F2F4"/>
    <padding android:left="20dp"/>
</shape>

去下划线

在 layout里面的xml文件内容添加:android:background="@null"即可去除EditText自带的下划线。


 <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:text="Hello World"
            android:textColor="#000"
            android:textSize="17sp"
            android:textStyle="bold"
 />

去焦点

可在使用EditText控件的外层布局添加android:focusable = "true",使外层在进入时自动获取焦点,从而使EditText控件不会自动获取焦点。具体做法如下:

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#F4F3F3"
    android:focusable = "true"
    android:focusableInTouchMode = "true">


 <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:text="Hello World"
            android:textColor="#000"
            android:textSize="17sp"
            android:textStyle="bold"
            />

</androidx.constraintlayout.widget.ConstraintLayout>

        以上便是对EditText在使用中经常遇到的问题总结以及解决的方案,希望可以帮助到有需要的人,喜欢的可以点赞收藏噢~

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值