Android精美登入介面設計
阿新 • • 發佈:2019-01-18
在網上在到一個登入介面感覺挺不錯的,給大家分享一下~先看效果圖:
這個Demo除了按鈕、小貓和Logo是圖片素材之外,其餘的UI都是通過程式碼實現的。
一、背景
背景藍色漸變,是通過一個xml檔案來設定的。程式碼如下:
background_login.xml
- <?xmlversion="1.0"encoding="utf-8"?>
- <shapexmlns:android="http://schemas.android.com/apk/res/android">
- <gradient
-
android:startColor
- android:endColor="#FF72CAE1"
- android:angle="45"
- />
- </shape>
startColor是漸變開始的顏色值,endColor是漸變結束的顏色值,angle是漸變的角度。其中#FFACDAE5中,FF是Alpha值,AC是RGB的R值,DA是RGB的G值,E5是RGB的B值,每個值在00~FF取值,即透明度、紅、綠、藍有0~255的分值,像要設定具體的顏色,可以在PS上的取色器上檢視設定。
二、圓角白框
效果圖上面的並不是白框,其實框是白色的,只是設定了透明值,也是靠一個xml檔案實現的。
background_login_div.xml
- <?xmlversion="1.0"encoding="UTF-8"?>
- <shapexmlns:android="http://schemas.android.com/apk/res/android">
- <solidandroid:color="#55FFFFFF"/>
- <!-- 設定圓角
- 注意: bottomRightRadius是左下角而不是右下角 bottomLeftRadius右下角-->
-
<cornersandroid:topLeftRadius
- android:bottomRightRadius="10dp"android:bottomLeftRadius="10dp"/>
- </shape>
三、介面的佈局
介面的佈局挺簡單的,就直接貼程式碼啦~
login.xml
- <?xmlversion="1.0"encoding="utf-8"?>
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="@drawable/background_login">
- <!-- padding 內邊距 layout_margin 外邊距
- android:layout_alignParentTop 佈局的位置是否處於頂部 -->
- <RelativeLayout
- android:id="@+id/login_div"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:padding="15dip"
- android:layout_margin="15dip"
- android:background="@drawable/background_login_div_bg">
- <!-- 賬號 -->
- <TextView
- android:id="@+id/login_user_input"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:layout_marginTop="5dp"
- android:text="@string/login_label_username"
- style="@style/normalText"/>
- <EditText
- android:id="@+id/username_edit"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:hint="@string/login_username_hint"
- android:layout_below="@id/login_user_input"
- android:singleLine="true"
- android:inputType="text"/>
- <!-- 密碼 text -->
- <TextView
- android:id="@+id/login_password_input"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@id/username_edit"
- android:layout_marginTop="3dp"
- android:text="@string/login_label_password"
- style="@style/normalText"/>
- <EditText
- android:id="@+id/password_edit"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_below="@id/login_password_input"
- android:password="true"
- android:singleLine="true"
- android:inputType="textPassword"/>
- <!-- 登入button -->
- <Button
- android:id="@+id/signin_button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@id/password_edit"
- android:layout_alignRight="@id/password_edit"
- android:text="@string/login_label_signin"
- android:background="@drawable/blue_button"/>
- </RelativeLayout>
- <RelativeLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- <TextViewandroid:id="@+id/register_link"
- android:text="@string/login_register_link"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="15dp"
- android:textColor="#888"
- android:textColorLink="#FF0066CC"/>
- <ImageViewandroid:id="@+id/miniTwitter_logo"
- android:src="@drawable/cat"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentRight="true"
- android:layout_alignParentBottom="true"
- android:layout_marginRight="25dp"
- android:layout_marginLeft="10dp"
- android:layout_marginBottom="25dp"/>
- <ImageViewandroid:src="@drawable/logo"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toLeftOf="@id/miniTwitter_logo"
- android:layout_alignBottom="@id/miniTwitter_logo"
- android:paddingBottom="8dp"/>
- </RelativeLayout>
- </LinearLayout>
四、Java原始檔
Java原始檔比較簡單,只是例項化Activity,去掉標題欄。