苏州高端网站设计建设,如何在网上推广app,泉州有那些网站建设公司,wordpress弹幕播放器正如题名#xff0c;在Android中的EditText是自带内边距的#xff0c;常规而言设置背景为null即可#xff0c;但是因为使用了并不熟悉的声明式框架#xff0c;本是几分钟解决的事儿#xff0c;却花费了小半天~ 简单的需求#xff0c;相关blog
Android进阶之路 - 去除Edi… 正如题名在Android中的EditText是自带内边距的常规而言设置背景为null即可但是因为使用了并不熟悉的声明式框架本是几分钟解决的事儿却花费了小半天~ 简单的需求相关blog
Android进阶之路 - 去除EditText内边距Android进阶之路 - EditText输入字体自适应
其实这只是一个很简单的小需求不想却遇到了一些小问题索性花一些时间去打牢一下基础 引发场景常见场景原始场景设置 background 场景background nullbackground 色值background drawable 设置 padding仅设置 padding设置 padding background Demo测试效果xml 引发场景
此场景正是我目前开发中需要适配的一个UI效果也因由此我又写了个Demo经过测试了一番后总结记录于此 我的思考
针对于整体布局而言以下俩种方式都可以使用初始出问题的时候我也都试过但当时没找到问题的关键
线性垂直布局帧布局EditTextTextView线性垂直布局线性水平布局EditTextTextView
总体布局方案搞定后主要就是针对于EditText常规处理
按理我仅需设置 background null 即可但是设置过后仅仅只是去除了底部线条上下边距依旧存在我给 EditText 设置了固定高度但导致EditText 显示不全(被遮挡)内边距依旧存在且覆盖在输入内容之上
因为我使用的是 声明式布局splitties框架 所以我就在想会不会是框架中有进行特殊设置为了排除问题我先拿同等处理方式在xml试了一下发现可以达到预期效果所以 background null 的方式是可行的但还不足够实现我们需求然后我睡了一觉后想“既然是上下边距的问题那去除内边距应该可以”经过尝试最终采用了 设置 padding background 的方式
我想现在采用这种布局方式的朋友应该还不是很多故此留一份伪代码用于各位了解我所遇场景和解决方式 关于在排错时我查看了框架是否内部有做设置但是简单看来好像并未设置 theme 之类的 然后我想着看看EditText的源码但是追的可能不太对等以后有时间在专研一下 搜索之后有人说 EditText 默认的 background 是一个 InsetDrawable 关于InsetDrawable 可自行查找学习一下我以下仅做简单记录 常见场景
以下场景仅是我个人经验而已从原始的EditText效果 - 去除原始默认效果 的处理方式和对应场景
原始场景
未经过任何设置的原始EditText默认会有底部线条上下内边距 示例 EditTextandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:hint原始的EditText /设置 background 场景
通过设置 EditText 的 background 可以去除其默认效果边距和底部横线我已知常见的有三种
null (较常用)色值drawable可以是shape也可以是图片 示例
background null EditTextandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:layout_marginTop10dpandroid:backgroundnullandroid:hintbackground 为 null /background 色值 EditTextandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:layout_marginTop10dpandroid:background#00000000android:hintbackground 为 色值 /background drawable
如不设置背景图默认会采用背景图高度 EditTextandroid:layout_widthmatch_parentandroid:layout_height40dpandroid:layout_marginTop10dpandroid:backgrounddrawable/icon_font_bgandroid:hintbackground 为 drawable /设置 padding
因为默认效果有上下边距所以我们也可以通过设置 padding达到基本效果
仅设置 padding
当仅设置 padding 的话默认的底部线条并不会消失 示例 EditTextandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:layout_marginTop10dpandroid:hintpadding 为 0android:padding0dp /设置 padding background
我所遇到的问题就是通过这种方式达到理想效果的 示例 EditTextandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:backgroundnullandroid:hintpadding0 backgroundnullandroid:padding0dp /Demo测试
这就是我用于测试 EditText 显示场景的Demo备忘于此
效果 xml
?xml version1.0 encodingutf-8?
androidx.appcompat.widget.LinearLayoutCompat xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationverticaltools:context.MainActivityEditTextandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:hint原始的EditText /EditTextandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:layout_marginTop10dpandroid:backgroundnullandroid:hintbackground 为 null /EditTextandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:layout_marginTop10dpandroid:background#00000000android:hintbackground 为 色值 /EditTextandroid:layout_widthmatch_parentandroid:layout_height40dpandroid:layout_marginTop10dpandroid:backgrounddrawable/icon_font_bgandroid:hintbackground 为 drawable /EditTextandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:layout_marginTop10dpandroid:hintpadding 为 0android:padding0dp /EditTextandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:layout_marginTop10dpandroid:backgroundnullandroid:hintpadding0 backgroundnullandroid:padding0dp //androidx.appcompat.widget.LinearLayoutCompat