如图,图中画线的下划线,一般如何实现的?
我测试,下划线没有途中的那么细

解决方案 »

  1.   

    如果这样你还是觉得不够细,就让美工给你切图,替换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>
      

  2.   

    一般是一些布局的嵌套,而不是单单去修改一个edittext控件,可操作性较强在edittext下方加入一个view,高度1px,不必设置单位为dp,不需要考虑适配,然后设置背景色,就有了如图所示的效果,前提你要给你的edittext设置drawble,否则在不同的机器上会显示不同的效果,在低版本会显示矩形框,在高版本机器上会在底部生成自带的边框,需要注意
      

  3.   

    改高度啊,View 的高度 改成 0.5 还不行 就继续调低
      

  4.   

    这是我截图的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>没看出它是怎么处理的,也没有用主题
      

  5.   

    <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的背景图实现的效果
      

  6.   

    打开手机的显示布局边界,可以很明显看到每个地方是怎么布局的,那根线应该不是属于edittext的,楼上应该是正解,代码里应该有获取焦点后替换图片的语句
      

  7.   

    两种方式:
    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"/>