使用ImageView 加上 Edittext做出自定义的输入框(EditText美化)
16lz
2021-01-24
使用过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>
更多相关文章
- Android(安卓)入门第十讲02-广播(广播概述,使用方法(系统广播,自定义
- Android开发指南-用户界面-事件处理
- Android(安卓)zar高速扫码程序,(比zxing快很多倍),包更小,扫码界面Xml
- Android(安卓)UI编程之自定义控件初步(上)——ImageButton
- Android设计登录界面、找回密码、注册功能
- android 自定义闪退Dialog 收集闪退信息
- Android全局主题样式控制,语言设置、主题颜色、字体大小、字体样
- Android(安卓)用户界面---Android如何描画View(How Android(安卓)
- Android多媒体开发 Pro Android(安卓)Media 第二章 创建自定义相