textedit底部下划线样式问题 如图,图中画线的下划线,一般如何实现的?我测试,下划线没有途中的那么细 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果这样你还是觉得不够细,就让美工给你切图,替换View里面的android:background背景即可<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff" android:orientation="vertical" android:padding="8dp" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@null" android:hint="请输入账号" android:textColor="#333333" android:textColorHint="#969696" /> <View android:layout_width="match_parent" android:layout_height="1dp" android:layout_marginTop="6dp" android:background="#64aab2" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:orientation="vertical" > <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@null" android:hint="请输入密码" android:textColor="#333333" android:textColorHint="#969696" /> <View android:layout_width="match_parent" android:layout_height="1dp" android:layout_marginTop="6dp" android:background="#e1e1e1" /> </LinearLayout></LinearLayout> 一般是一些布局的嵌套,而不是单单去修改一个edittext控件,可操作性较强在edittext下方加入一个view,高度1px,不必设置单位为dp,不需要考虑适配,然后设置背景色,就有了如图所示的效果,前提你要给你的edittext设置drawble,否则在不同的机器上会显示不同的效果,在低版本会显示矩形框,在高版本机器上会在底部生成自带的边框,需要注意 改高度啊,View 的高度 改成 0.5 还不行 就继续调低 这是我截图的APP反编译后的布局源码<LinearLayout android:gravity="center_vertical" android:orientation="horizontal" android:id="@id/account_container" android:background="@drawable/divider_blue" android:paddingBottom="@dimen/dimen_8" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/dimen_44" android:layout_below="@id/ll_layout"> <ImageView android:layout_gravity="center|right" android:id="@id/account_tag" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/dimen_10" android:src="@drawable/username_icon_backup_kingsoft" /> <EditText android:textSize="@dimen/font_16" android:textColor="@color/font_form_editview" android:id="@id/login_username_edt" android:background="@null" android:layout_width="0.0dip" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/dimen_30" android:hint="@string/input_username" android:singleLine="true" android:includeFontPadding="false" android:layout_weight="1.0" /> <ImageView android:layout_gravity="center_vertical" android:id="@id/clear_user_name_img" android:visibility="gone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="@dimen/dimen_10" android:src="@drawable/delete_user" /> <CheckBox android:layout_gravity="center|right" android:id="@id/cb_login_select_user" android:background="@drawable/login_select_user_bg" android:paddingRight="@dimen/dimen_3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="@dimen/dimen_5" android:checked="false" android:button="@null" /> </LinearLayout>没看出它是怎么处理的,也没有用主题 <LinearLayout android:id="@id/account_container" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/ll_layout" android:layout_marginTop="@dimen/dimen_44" android:background="@drawable/divider_blue"//这里背景图应该是底部一根脸色线条,其余为透明或者白色 android:gravity="center_vertical" android:orientation="horizontal" android:paddingBottom="@dimen/dimen_8" >//这里的意思是LinearLayout里面内容离底部的距离 <ImageView android:id="@id/account_tag" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center|right" android:layout_marginLeft="@dimen/dimen_10" android:src="@drawable/username_icon_backup_kingsoft" /> <EditText android:id="@id/login_username_edt" android:layout_width="0.0dip" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/dimen_30" android:layout_weight="1.0" android:background="@null" android:hint="@string/input_username" android:includeFontPadding="false" android:singleLine="true" android:textColor="@color/font_form_editview" android:textSize="@dimen/font_16" /> <ImageView android:id="@id/clear_user_name_img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="@dimen/dimen_10" android:src="@drawable/delete_user" android:visibility="gone" /> <CheckBox android:id="@id/cb_login_select_user" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center|right" android:layout_marginRight="@dimen/dimen_5" android:background="@drawable/login_select_user_bg" android:button="@null" android:checked="false" android:paddingRight="@dimen/dimen_3" /></LinearLayout>因此他这个Edit底部的蓝色细线就是靠父布局LinearLayout的背景图实现的效果 打开手机的显示布局边界,可以很明显看到每个地方是怎么布局的,那根线应该不是属于edittext的,楼上应该是正解,代码里应该有获取焦点后替换图片的语句 两种方式:1、给EditText设置下线背景shape.xml<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!--底层使用蓝色填充色--> <item android:left="8dp" android:right="8dp"> <shape> <solid android:color="@color/colorPrimary" /> </shape> </item> <!--上面一层距离底层的顶部1dp,类似marginTop,填充色为白色,这样就形成了一个带有蓝色顶部边线的白色背景的图--> <item android:bottom="1dp"> <shape> <solid android:color="@color/white" /> </shape> </item></layer-list>2、直接用<View>实现: <View android:background="@color/colorPrimary" android:layout_width="match_parent" android:layout_height="0.5dp"/> 如何在照片中抠取一块固定的不规则图形 android 怎么释放图片资源? 找 安卓的标签 android 媒体播放网络文件错误 android 传递图片的问题,急用 如何调用系统的wifi管理界面 EditText SQLite 一个Activity和xml 的问题 开启一个AsyncTask异步任务,抓取网络数据,然后在OnPost里填充listview的adapter,为何异步任务抓取数据为空 小白初学安卓,出现这个,求大佬解答 Android如何用socket将手机中文件的数据上传到服务器(服务器是自己编写代码)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
android:padding="8dp" > <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" > <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:hint="请输入账号"
android:textColor="#333333"
android:textColorHint="#969696" /> <View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="6dp"
android:background="#64aab2" />
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="vertical" > <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:hint="请输入密码"
android:textColor="#333333"
android:textColorHint="#969696" /> <View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="6dp"
android:background="#e1e1e1" />
</LinearLayout></LinearLayout>
<ImageView android:layout_gravity="center|right" android:id="@id/account_tag" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/dimen_10" android:src="@drawable/username_icon_backup_kingsoft" />
<EditText android:textSize="@dimen/font_16" android:textColor="@color/font_form_editview" android:id="@id/login_username_edt" android:background="@null" android:layout_width="0.0dip" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/dimen_30" android:hint="@string/input_username" android:singleLine="true" android:includeFontPadding="false" android:layout_weight="1.0" />
<ImageView android:layout_gravity="center_vertical" android:id="@id/clear_user_name_img" android:visibility="gone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="@dimen/dimen_10" android:src="@drawable/delete_user" />
<CheckBox android:layout_gravity="center|right" android:id="@id/cb_login_select_user" android:background="@drawable/login_select_user_bg" android:paddingRight="@dimen/dimen_3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="@dimen/dimen_5" android:checked="false" android:button="@null" />
</LinearLayout>没看出它是怎么处理的,也没有用主题
android:id="@id/account_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/ll_layout"
android:layout_marginTop="@dimen/dimen_44"
android:background="@drawable/divider_blue"//这里背景图应该是底部一根脸色线条,其余为透明或者白色
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="@dimen/dimen_8" >//这里的意思是LinearLayout里面内容离底部的距离 <ImageView
android:id="@id/account_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|right"
android:layout_marginLeft="@dimen/dimen_10"
android:src="@drawable/username_icon_backup_kingsoft" /> <EditText
android:id="@id/login_username_edt"
android:layout_width="0.0dip"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dimen_30"
android:layout_weight="1.0"
android:background="@null"
android:hint="@string/input_username"
android:includeFontPadding="false"
android:singleLine="true"
android:textColor="@color/font_form_editview"
android:textSize="@dimen/font_16" /> <ImageView
android:id="@id/clear_user_name_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="@dimen/dimen_10"
android:src="@drawable/delete_user"
android:visibility="gone" /> <CheckBox
android:id="@id/cb_login_select_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|right"
android:layout_marginRight="@dimen/dimen_5"
android:background="@drawable/login_select_user_bg"
android:button="@null"
android:checked="false"
android:paddingRight="@dimen/dimen_3" /></LinearLayout>
因此他这个Edit底部的蓝色细线就是靠父布局LinearLayout的背景图实现的效果
1、给EditText设置下线背景shape.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!--底层使用蓝色填充色-->
<item
android:left="8dp"
android:right="8dp">
<shape>
<solid android:color="@color/colorPrimary" />
</shape>
</item> <!--上面一层距离底层的顶部1dp,类似marginTop,填充色为白色,这样就形成了一个带有蓝色顶部边线的白色背景的图-->
<item
android:bottom="1dp">
<shape>
<solid android:color="@color/white" />
</shape>
</item>
</layer-list>2、直接用<View>实现:
<View
android:background="@color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="0.5dp"/>