昨天简单写了下记住密码和显示密码,由于时间有限随便写了一下,今天有时间,给大家详细的写一下比较好看的登录界面。
跟往常一样,废话不多少,先上一张效果图吧
接下来先教大家弄一下这个渐变布局,喜欢别的颜色可以更改,在drawable里新建一个文件,代码如下:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:startColor="#009393" android:endColor="#bbffbb" android:angle="90"/> </shape>
然后开始写布局,布局就是一个简单的用线性布局包裹着的一个布局,直接粘上代码让大家看看吧:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:background="@drawable/sha" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="账号登录" android:layout_gravity="center" android:layout_marginTop="85dp" android:textColor="#ffffff" android:textSize="30sp"/> <LinearLayout android:layout_width="match_parent" android:layout_height="40dp" android:orientation="horizontal" android:layout_marginLeft="60dp" android:layout_marginRight="60dp" android:layout_marginTop="15dp" android:background="#ffffff"> <EditText android:id="@+id/ed_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:layout_marginTop="10dp" android:layout_marginLeft="10dp" android:hint="请输入账号" android:textColorHint="#f0f0f0" android:background="@null"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="40dp" android:orientation="horizontal" android:layout_marginLeft="60dp" android:layout_marginRight="60dp" android:layout_marginTop="15dp" android:background="#ffffff"> <EditText android:id="@+id/ed_pass" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:layout_marginTop="10dp" android:layout_marginLeft="10dp" android:hint="请输入密码" android:inputType="textPassword" android:textColorHint="#f3f3f3" android:background="@null"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="40dp" android:orientation="horizontal" android:layout_marginLeft="60dp" android:layout_marginRight="60dp" android:layout_marginTop="15dp"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <CheckBox android:id="@+id/ck_pass" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="记住密码" android:gravity="center" android:textColor="#ffffff"/> <CheckBox android:id="@+id/ck_xian" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:text="显示密码" android:gravity="center" android:textColor="#ffffff"/> <TextView android:id="@+id/tv_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#ffffff" android:gravity="center" android:layout_marginTop="8dp" android:layout_alignParentRight="true" android:text="注册账号"/> </RelativeLayout> </LinearLayout> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="65dp" android:layout_marginRight="65dp" android:layout_marginTop="15dp" android:background="#009393" android:text="登录" android:onClick="log" android:textColor="#ffffff" android:textSize="20sp"/> </LinearLayout>
好了,写到这里你就可以运行一下自己的应用,就会发现你也有这样的登录界面,注明一点:最外层的线性布局的背景就是最开始咱们写的那个文件,引用一下就好了,欢迎大家在这里相互交流。