Almost all android application will have login or registration process in order to authenticate a user. In this article i will be demonstrating how to design android login and registration screen design (note that it just designing the screens – no database connection or user validation).
The final output screenshots of this tutorial will be like below image
To achieve login/registration screen design I am merging multiple android layouts. I placed Scroll View as a parent element. This Scroll View makes your screen scroll in vertical direction to avoid hiding exceeding objects on the screen. Inside scroll view I placed Relative View. The main reason for using Relative View is to make footer always stick at the bottom. Finally I am using Linear Layouts for placing Header, Form and Footer. See the following diagram to get an idea about the layouts I used.
Designing Login Screen
In this tutorial the main focus is to creating android login, registration screens and navigating/switching between them.
1. Create a new project by going to File ⇒ New Android Project. Fill all the details and name your activity asLoginActivity.
2. Once the project is created, create a new activity class in your project src directory and name it asRegisterActivity.java ( Right Click on src/package ⇒ New ⇒ Class)
3. Now we need to create a layout for login screen. Under res/layouts create a new xml file and name it aslogin.xml
( Right Click on res/layout ⇒ New ⇒ Android XML File)
4. In login.xml type following code( Here i am giving code for basic layout)
2. Once the project is created, create a new activity class in your project src directory and name it asRegisterActivity.java ( Right Click on src/package ⇒ New ⇒ Class)
3. Now we need to create a layout for login screen. Under res/layouts create a new xml file and name it aslogin.xml
( Right Click on res/layout ⇒ New ⇒ Android XML File)
4. In login.xml type following code( Here i am giving code for basic layout)
<? xml version = "1.0" encoding = "utf-8" ?> < ScrollView android:layout_width = "fill_parent" android:layout_height = "fill_parent" android:fillViewport = "true" > < RelativeLayout android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:background = "#ffffff" > <!-- Header Starts--> <!-- Header Ends --> <!-- Footer Start --> <!-- Place footer next to header to set z-index property to minus value --> <!-- Footer Ends --> <!-- Login Form --> <!-- Login Form Ends --> </ RelativeLayout > </ ScrollView > |
⇒Designing Header ( with Logo & Gradient Background )
In login screen we have header with a logo and gradient background color. Design your logo with different dimensions for high-density( 72px height), medium density ( 48 px height) and low density (36px height).
5. Create a new xml file under res/layout and name it as header_gradient.xml and type the following code
<? xml version = "1.0" encoding = "utf-8" ?> < gradient android:startColor = "#24b2eb" android:centerColor = "#4ccbff" android:endColor = "#24b2eb" android:angle = "270" /> < corners android:radius = "5dp" /> </ shape > |
6. In login.xml add the following code between the header comments.
<!-- Header Starts--> < LinearLayout android:id = "@+id/header" android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:background = "@layout/header_gradient" android:paddingTop = "5dip" android:paddingBottom = "5dip" > <!-- Logo Start--> < ImageView android:src = "@drawable/logo" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:layout_marginLeft = "10dip" /> <!-- Logo Ends --> </ LinearLayout > <!-- Header Ends --> |
⇒Designing Footer ( with background repeat image )
In login screen footer has a background repeat image. When you flip the device in horizontal direction you can see the footer with background repeated image.
7. Create a new xml file under res/layout and name it as footer_repeat.xml and type the following code.
<? xml version = "1.0" encoding = "utf-8" ?> android:src = "@drawable/repeat_bg" android:tileMode = "repeat" /> |
8. In login.xml type the following code between footer comments
<!-- Footer Start --> < LinearLayout android:id = "@+id/footer" android:layout_width = "fill_parent" android:layout_height = "90dip" android:background = "@layout/footer_repeat" android:layout_alignParentBottom = "true" > </ LinearLayout > <!-- Footer Ends -->
⇒Designing Login Form
Designing the registration form
Switching from Login screen to Registration screen
11. Open your RegisterActivity.java and modify your code to following. To switch back to login screen just call finish(). It will close the registration screen, so login screen will be shown
|
沒有留言:
張貼留言