1、简述
EditText在日常开发中使用的频率很高,而针对不同的业务需求在使用上也有许多知识点是我们需要去推敲总结学习记忆的。本文主要记录输入框使用的技巧,包括输入框本身的关于背景、光标技巧以及设计到软键盘的使用和布局方面的问题。
2、EditText相关技巧
下面我们需要分析一个通用的输入提交案例,包含标题、主体内容以及提交按钮的相对布局,如下段代码所展示。
针对页面我们提出如下几个问题:
1、光标颜色粗细不喜欢,如何设置?设置gravity为何定位到输入框输入时光标这么西呢?如何调整
2、进入页面时软键盘默认弹出,如何设置软键盘在页面加载和结束关闭?
3、我并不想让布局获取焦点而且光标不闪烁这时怎么处理?
4、输入框获取焦点有时底部控件会顶上去置于软键盘之上如何处理?
5、为何有时相对布局设置了居于底部,但当软键盘弹起时为何布局不会顶上去?
6、如何点击空白处关闭软件盘呢
不知道各位和我一样有这些困惑呢,下面我就一一来针对问题给出自己的见解
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/title"
android:text="标题"
android:gravity="center_vertical"
android:background="#0f0"
android:layout_width="match_parent"
android:layout_height="50dp">
</TextView>
<Button
android:textSize="16sp"
android:textColor="@color/white"
android:layout_alignParentBottom="true"
android:text="登录"
android:background="@color/color_red"
android:id="@+id/btnSubmit"
android:layout_width="match_parent"
android:layout_height="50dp" />
<ScrollView
android:layout_below="@id/title"
android:layout_above="@id/btnSubmit"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
andr