登錄界面android
1. 如何設計android的登錄界面
在網上在到一個登錄界面感覺挺不錯的,給大家分享一下~先看效果圖:
這個Demo除了按鈕、小貓和Logo是圖片素材之外,其餘的UI都是通過代碼實現的。
?
一、背景
背景藍色漸變,是通過一個xml文件來設置的。代碼如下:
background_login.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:andro>
<gradient
android:startColor="#FFACDAE5"
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
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:andro>
<solid android:color="#55FFFFFF" />
<!-- 設置圓角
注意: bottomRightRadius是左下角而不是右下角 bottomLeftRadius右下角-->
<corners android:topLeftRadius="10dp" android:topRightRadius="10dp"
android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp"/>
</shape>
?
三、界面的布局
界面的布局挺簡單的,就直接貼代碼啦~
login.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:andro
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:
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:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
android:text="@string/login_label_username"
/>
<EditText
android:
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:
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"
/>
<EditText
android:
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:
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" >
<TextView android:
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" />
<ImageView android:
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" />
<ImageView android: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>
2. 如何使用Android Studio開發用戶登錄界面
在Android Studio開發用戶登錄界面時,首先確保你已配置好基本運行環境及SDK。項目開始前,通過右鍵點擊new->Mole,選擇Android Application,並將其名稱改為你的項目名稱。同時選擇支持的Android版本。接下來選擇Blank Activity,然後點擊next,直至最後點擊finish完成項目的創建。
在project目錄下,你會看到新創建的登錄項目。展開res/layout文件夾,點擊打開activity_main.xml文件,這里你將編寫登錄界面。這是初始的主界面,尚未經過我們編寫的界面。Android Studio提供了一個強大的預覽功能,非常實用。
將activity_main.xml的代碼替換成以下內容:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" android:gravity="center_vertical" android:stretchColumns="0,3">
<TextView android:text="賬 號:" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="24px" />
<EditText android:id="@+id/account" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="24px" android:minWidth="220px"/>
<TextView android:text="密 碼:" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<EditText android:id="@+id/pwd" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minWidth="220px" android:textSize="24px" android:inputType="textPassword"/>
<Button android:id="@+id/login" android:text="登錄" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<Button android:id="@+id/quit" android:text="退出" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
完成上述代碼替換後,使用Android手機進行測試,大功告成。
你的支持是我前進的動力,記得給予好評和採納,答題不易,互相幫助。
3. 如何使用Android Studio開發用戶登錄界面
一個登錄界面需要有:
登錄、注冊按鈕(Button)
用戶名、密碼輸入框(TextView,EditView)
用戶協議連接
忘記密碼按鈕
想好的有哪些控制項後,開始設計界面大概樣式,比如這個樣子:
安卓登錄界面就寫完了。