1. 程式人生 > >安卓好看的登入介面

安卓好看的登入介面

大家好,今天開始寫我的第二篇部落格,昨天簡單寫了下記住密碼和顯示密碼,由於時間有限隨便寫了一下,今天有時間,給大家詳細的寫一下比較好看的登入介面。

跟往常一樣,廢話不多少,先上一張效果圖吧

接下來先教大家弄一下這個漸變佈局,喜歡別的顏色可以更改,在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>

好了,寫到這裡你就可以執行一下自己的應用,就會發現你也有這樣的登入介面,註明一點:最外層的線性佈局的背景就是最開始咱們寫的那個檔案,引用一下就好了,歡迎大家在這裡相互交流。