- How to Create User Interface Login & Register with Android Studio
- Adjustment of several layouts :
- Connect fragments with viewpager
- Login Screen Design In Android Studio
- Creating New Android Project (Login Screen Design In Android Studio)
- Add Colors
- Add Background Image And Logo
- Add Vector Drawable
- Android Material Design Login Form XML UI Design
- Android Example: Android Material Design Login Form XML UI Design
- Import Design Support Library
- XML Layout File
- XML Drawable File
- Java Activity File
- Android Login and Registration Screen Design
- Android Login and Registration Screens Example
- activity_main.xml
- registration.xml
- MainActivity.java
- RegistrationActivity.java
- AndroidManifest.xml
- Output of Android Login & Registration Screens Example
How to Create User Interface Login & Register with Android Studio
ok, this is my first article in Medium. In this section, I want to share with you about the User Interface on Android and we will create a Login page and a Register page. Some components that I will use:
1. Viewpager
2. Fragment
3. Edittext
4. Button
5. Textview
6. Imageview
What about the results? let’s coding (follow step by step)
- Of course we must already have an Android Studio. if not, you can download it first on the official Android Studio website. If you already have one, please open your Android studio.
2. We create a new project by clicking “Start a new Android Studio project”. Fill in the application name column with “LoginApp”, then click next.
3. Select the minimum SDK you need or want, then click next.
4. Select “Empty Activity” and click next. After that, the “Activity Name” and “Layout Name” columns will appear, in this section just leave it like that, then click finish.
After you click finish, Android Studio will make you an Application with the name “LoginApp”.
After the application is successfully built, you can simply make adjustments to the following sections:
Open the colors.xml file in app/res/values/colors.xml, and change it like this:
Create a folder with the name “font” in the res folder, by right clicking on the res directory, select new / directory and name it “font”. After that, copy this font into font directory. (download the font 1 and font 2).
Create some Drawable Resource File in the drawable directory, by right-clicking on the drawable directory, select new / Drawable Resource File.
After that open file styles.xml and change like this :
Add the theme property in the Main Activity in the manifest, in the app / manifests / AndroidManifest.xml folder
So the AndroidManifest.xml file will be as follows:
After all the steps above are done, then make 2 fragments with the name fragment_login and fragment_register in the layout directory, by right-clicking on the layout directory, New/Fragment/Fragment (Blank)
Uncheck:
include fragment factory methods? and include interface methods?
Adjustment of several layouts :
change the activity_main.xml layout, fragment_login.xml and fragment_register.xml so that it will be as below
Open the strings.xml file in the res / values / strings.xml directory and change it to something like the following :
So that the overall structure of the project will be as follows :
Connect fragments with viewpager
Create an inner class in the MainActivity.java class with the name AuthenticationPapterAdapter. This class is a derivative of the FragmentPagerAdapter class and serves to connect Fragments with ViewPager,
Then call the class in the onCreate() method in MainActivity.java and connect with viewpager
So the MainActivity.java class will be like this
The display of the final application will be like this
Источник
Login Screen Design In Android Studio
Hello Friends today we are going to design login screen by using LinearLayout. Login screen should be attractive it is first view which user interact with that’s why is should be user friendly as well. We will begin our designing by simply creating a new project.Login Screen Design In Android Studio.
Creating New Android Project (Login Screen Design In Android Studio)
- Create a new project in Android Studio File–>New–>New Project.
- Enter Application Name, Package Name, Select Empty Activity and click on finish.
Add Colors
- Open App–>values–>colors.xml
- Specify colors which we are going to use in app.
Add Background Image And Logo
- Add background image and logo of your app.
- I will attack the sample background image and logo at the end of this blog.
- Paste file to mipmap folder.
Add Vector Drawable
- Add vector drawable which we are going to use in our project.
- Right click on Drawable folder then New–>Vector Asset.
- click on Icon then Select Icon and add it to on drawable folder.
- Add three vectors Person,Lock,Lock Open from Vector Asset.
- You can change color of vectordrawable. To change color open that drawable and change FillColor value.
Источник
Android Material Design Login Form XML UI Design
In this tutorial, I am going to show how to create material design login form XML UI design. Many android applications have login and registration system. Here I have used only XML to create login screen. You have to create a drawable XML file for profile picture background color to make rounded. And you can use icons according to your wish here I have not provided icons. For EditText field icon should be small (24*24) to make attractive.
Android Example: Android Material Design Login Form XML UI Design
Let’s start by creating new android project with the project name Android Material Design Login Form or some else.
Import Design Support Library
In this project I have used TextInputLayout which is available in android design support library, so you have to add design support library in build.gradle file if not have.
XML Layout File
In XML layout file I have used RelativeLayout, LinearLayout, TextInputLayout, EditText, Button, ImageButton and TextView with different xml attribute to make material design login form UI design. Following is the complete content of XML layout file.
XML Drawable File
Create a new XML file in res/drawable to make rounded in profile picture background. Following is the complete content of user_profile_image_background.xml file.
Java Activity File
Default code of java activity file will look like this.
Источник
Android Login and Registration Screen Design
To allow only registered users to our android application, we need to implement login and registration screens to ask the users to register first, then login to the application to get an access for the content in an application.
Now we will see how to implement login and registration screens using material design in android application like as shown following.
Android Login and Registration Screens Example
Following is the example of creating the login and registration screens in android application to allow only valid users based on our requirements.
Create a new android application using android studio and give names as LoginExample. In case if you are not aware of creating an app in android studio check this article Android Hello World App.
Once we create an application, open activity_main.xml file from \res\layout folder path and write the code like as shown below.
activity_main.xml
xml version= «1.0» encoding= «utf-8» ?>
LinearLayout xmlns: android = «http://schemas.android.com/apk/res/android»
android :orientation= «vertical» android :layout_width= «match_parent»
android :layout_height= «match_parent» >
TextView
android :id= «@+id/loginscrn»
android :layout_width= «wrap_content»
android :layout_height= «wrap_content»
android :layout_marginTop= «80dp»
android :text= «Login»
android :textSize= «25dp»
android :textStyle= «bold»
android :layout_gravity= «center»/>
TextView
android :id= «@+id/fstTxt»
android :layout_width= «wrap_content»
android :layout_height= «wrap_content»
android :layout_marginLeft= «100dp»
android :layout_marginTop= «20dp»
android :text= «Email»/>
EditText
android :id= «@+id/txtEmail»
android :layout_width= «wrap_content»
android :layout_height= «wrap_content»
android :layout_marginLeft= «100dp»
android :ems= «10»/>
TextView
android :id= «@+id/secTxt»
android :layout_width= «wrap_content»
android :layout_height= «wrap_content»
android :text= «Password»
android :layout_marginLeft= «100dp»/>
EditText
android :id= «@+id/txtPwd»
android :layout_width= «wrap_content»
android :layout_height= «wrap_content»
android :layout_marginLeft= «100dp»
android :inputType= «textPassword»
android :ems= «10»/>
Button
android :id= «@+id/btnLogin»
android :layout_width= «wrap_content»
android :layout_height= «wrap_content»
android :layout_marginLeft= «100dp»
android :text= «Login»/>
TextView android :id= «@+id/lnkRegister»
android :layout_width= «match_parent»
android :layout_height= «wrap_content»
android :layout_marginTop= «40dp»
android :text= «New to Tutlane? Register here»
android :gravity= «center»
android :textSize= «20dp»
android :textColor= «#3F51B5»/>
LinearLayout >
Now we will create another layout resource file registration.xml in \res\layout path to allow new users to register in our application for that right click on your layout folder à Go to New à select Layout Resource File and give name as registration.xml.
Once we create a new layout resource file registration.xml, open it and write the code like as shown below
registration.xml
xml version= «1.0» encoding= «utf-8» ?>
LinearLayout xmlns: android = «http://schemas.android.com/apk/res/android»
android :orientation= «vertical» android :layout_width= «match_parent»
android :layout_height= «match_parent» >
TextView
android :id= «@+id/loginscrn»
android :layout_width= «wrap_content»
android :layout_height= «wrap_content»
android :layout_marginTop= «80dp»
android :text= «Registration»
android :textSize= «25dp»
android :textStyle= «bold»
android :layout_gravity= «center»/>
TextView
android :id= «@+id/fstTxt»
android :layout_width= «wrap_content»
android :layout_height= «wrap_content»
android :layout_marginLeft= «100dp»
android :layout_marginTop= «20dp»
android :text= «Full Name»/>
EditText
android :id= «@+id/txtName»
android :layout_width= «wrap_content»
android :layout_height= «wrap_content»
android :layout_marginLeft= «100dp»
android :ems= «10»/>
TextView
android :id= «@+id/secTxt»
android :layout_width= «wrap_content»
android :layout_height= «wrap_content»
android :text= «Email»
android :layout_marginLeft= «100dp»/>
EditText
android :id= «@+id/txtEmail»
android :layout_width= «wrap_content»
android :layout_height= «wrap_content»
android :layout_marginLeft= «100dp»
android :ems= «10»/>
TextView
android :id= «@+id/thirdTxt»
android :layout_width= «wrap_content»
android :layout_height= «wrap_content»
android :text= «Password»
android :layout_marginLeft= «100dp»/>
EditText
android :id= «@+id/txtPwd»
android :layout_width= «wrap_content»
android :layout_height= «wrap_content»
android :layout_marginLeft= «100dp»
android :inputType= «textPassword»
android :ems= «10»/>
Button
android :id= «@+id/btnLogin»
android :layout_width= «wrap_content»
android :layout_height= «wrap_content»
android :layout_marginLeft= «100dp»
android :text= «Login»/>
TextView android :id= «@+id/lnkLogin»
android :layout_width= «match_parent»
android :layout_height= «wrap_content»
android :layout_marginTop= «40dp»
android :text= «Already Registered? Login here»
android :gravity= «center»
android :textSize= «20dp»
android :textColor= «#3F51B5»
android :onClick= «test»/>
LinearLayout >
Now open your main activity file MainActivity.java from \java\com.tutlane.loginexample path and write the code like as shown below
MainActivity.java
package com.tutlane.loginexample;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity <
@Override
protected void onCreate(Bundle savedInstanceState) <
super .onCreate(savedInstanceState);
setContentView(R.layout. activity_main );
TextView register = (TextView)findViewById(R.id. lnkRegister );
register.setMovementMethod(LinkMovementMethod.getInstance());
register.setOnClickListener( new View.OnClickListener() <
@Override
public void onClick(View v) <
Intent intent = new Intent(MainActivity. this , RegistrationActivity. class );
startActivity(intent);
>
>);
>
>
If you observe the above code, whenever the user click on register link, we are redirecting the user from login screen to registration screen using “RegistrationActivity” for that create another activity file RegistrationActivity.java in \java\com.tutlane.loginexample path.
Now right click on your application folder à Go to New à select Java Class and give name as RegistrationActivity.java.
Once we create a new activity file RegistrationActivity.java, open it and write the code like as shown below
RegistrationActivity.java
package com.tutlane.loginexample;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.widget.TextView;
/**
* Created by tutlane on 08-01-2018.
*/
public class RegistrationActivity extends AppCompatActivity <
@Override
protected void onCreate(Bundle savedInstanceState) <
super .onCreate(savedInstanceState);
setContentView(R.layout. registration );
TextView login = (TextView)findViewById(R.id. lnkLogin );
login.setMovementMethod(LinkMovementMethod.getInstance());
login.setOnClickListener( new View.OnClickListener() <
@Override
public void onClick(View v) <
Intent intent = new Intent(RegistrationActivity. this , MainActivity. class );
startActivity(intent);
>
>);
>
>
Now we need to add this newly created activity in AndroidManifest.xml file in like as shown below.
AndroidManifest.xml
xml version= «1.0» encoding= «utf-8» ?>
manifest xmlns: android = «http://schemas.android.com/apk/res/android»
package= «com.tutlane.loginexample» >
application
android :allowBackup= «true»
android :icon= «@mipmap/ic_launcher»
android :label= «@string/app_name»
android :roundIcon= «@mipmap/ic_launcher_round»
android :supportsRtl= «true»
android :theme= «@style/AppTheme» >
activity android :name= «.MainActivity» >
intent-filter >
action android :name= «android.intent.action.MAIN»/>
category android :name= «android.intent.category.LAUNCHER»/>
intent-filter >
activity >
activity android :name= «.RegistrationActivity» android :label= «Registration» > activity >
application >
manifest >
If you observe above example, we created login and registration screens and added all the activities in AndroidManifest.xml file.
Output of Android Login & Registration Screens Example
When we run the above example in the android emulator we will get a result like as shown below.
If you observe above result, initially we are getting a login screen and redirecting the user to the registration screen whenever the user clicks Register Here link.
This is how we can create login and registration screens using material design in android applications to allow valid users based on our requirements.
Источник