使用ImageView 加上 Edittext做出自定义的输入框(EditText美化)

使用过Android不同版本,或者不同的Android的rom的同学应该都知道,Android的EditText的样式在不同它们上的显示是各式各样;

那我们能不能通过什么途径来让它们的样子统一起来呢?答案是肯定的...

这是我做的一个登录界面,虽然还有些粗糙,但是实现了输入框样式的统一;

我的实现思路是这样的(可能大家会有不同的方案,欢迎分享),首先定义一个RelativeLayout,然后再里面放一个ImageView,ImageView的背景色使用白色,高度确定,这里是120dp;

然后再定义一个EditText,不要背景(这样就实现了去掉输入框的边框),上方和左方与图片对齐;然后再弄一个分界线,我这里用的是ImageView 0.5dp,颜色是灰色;

下面在来一个EditText,左边和下边跟ImageView对齐;然后调节下字体颜色大小之类的,就完成了这个功能...

具体界面布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#1885DC"
    android:gravity="center_horizontal"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp"
        android:text="@string/title"
        android:textColor="@android:color/white"
        android:textSize="36sp" />

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="30dp" >

        <ImageView
            android:id="@+id/img_bg"
            android:layout_width="fill_parent"
            android:layout_height="120dp"
            android:background="#FFF"
            android:contentDescription="@string/app_name" />

        <EditText
            android:id="@+id/et_username"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_alignLeft="@+id/img_bg"
            android:layout_alignTop="@+id/img_bg"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="@null"
            android:hint="@string/hint_username"
            android:inputType="number"
            android:textSize="16sp" />

        <ImageView
            android:id="@+id/login_driver"
            android:layout_width="match_parent"
            android:layout_height="0.5dp"
            android:layout_below="@+id/et_username"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:background="@android:color/darker_gray"
            android:contentDescription="@string/app_name" />

        <EditText
            android:id="@+id/et_password"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_alignBottom="@+id/img_bg"
            android:layout_alignLeft="@+id/img_bg"
            android:layout_below="@+id/et_username"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="@null"
            android:hint="@string/hint_password"
            android:inputType="textPassword"
            android:textSize="16sp" />

        <Button
            android:onClick="login"
            android:id="@+id/button_login"
            android:layout_width="fill_parent"
            android:layout_height="45dp"
            android:layout_below="@+id/et_password"
            android:layout_marginTop="5dp"
            android:background="@drawable/login_button"
            android:text="@string/login"
            android:textColor="#FFF"
            android:textSize="16sp" />
        <Button
            android:id="@+id/button_visit"
            android:onClick="visit"
            android:layout_width="fill_parent"
            android:layout_height="45dp"
            android:layout_below="@+id/button_login"
            android:layout_marginTop="5dp"
            android:background="@drawable/visitor_button"
            android:text="@string/visitor"
            android:textColor="#FFF"
            android:textSize="16sp" />
        <Spinner 
            android:layout_below="@+id/button_visit"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/banji_spinner"
            android:visibility="gone"/>
    </RelativeLayout>

</LinearLayout>












  • 7
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值