Android Studio also provides developers with a variety of template options, which greatly increases development speed. These templates can automatically create activity and the necessary XML files. You can also use these templates to create a more basic Android application and run it in a physical device or simulator.
In Android Studio, we can create a corresponding template together when we create a new activity. Right-click on "Package name" in the project browser on the left side of the window and select "New" from the menu, then click "Activity" from the list of options. Android Studio will then list a list of templates for developers, including blank activity, fullscreen activity, and tabbed activity.
You can also select "Image Asset" from the menu, and the next wizard will guide us through the process of creating a step-by-step procedure. Let's take a look at how to create a new set of activity based on the login activity template. First select the Login activity option in the Acivity Template list to start the Create wizard.
As you can see in the above, I have named the newly created activity loginactivity--the layout name--for activity login and added a title named sign in to the activity. By default, the include Google + sign in item in the dialog box is checked. Since we are not going to use the Google + sign-in feature in today's example, uncheck the Tick option.
You can choose to set the hierarchical Parent (hierarchy) for this new activity. So when we click the Back button on the device, the app will navigate back to the previous interface. We leave this field blank. After clicking "Finish", Android Studio will create the necessary files and folders for us. If everything goes well, we will see new activity and layout in the project.
The next piece of work is to set up the new activity in the manifest file so that it can be used as the primary activity when the application starts. Please take a look at the following manifest file content, where the Loginactivity class has its own active node.
<application android:allowbackup= "true" android:icon= "@drawable/ic_launcher" android:label= "@ String/app_name " android:theme=" @style/apptheme "> <activity android:name=" Com.tuts.HelloWorld.MainActivity " android:label=" @string/app_name "> <intent-filter> < Action android:name= "Android.intent.action.MAIN"/> <category android:name= " Android.intent.category.LAUNCHER "/> </intent-filter> </activity> <activity android:name= "com.tuts.HelloWorld.LoginActivity" android:label= "@string/title_activity_login" Android:windowsoftinputmode= "Adjustresize|statevisible" > </activity> </application>
In order to launch the loginactivity we just created in the application, we first need to remove the active node from the original Loginactivity class. Then use com.tuts.HelloWorld.LoginActivity instead of the previous com.tuts.HelloWorld.MainActivity. In this way, the application will now use the Loginactivity class as its main activity.
<application android:allowbackup= "true" android:icon= "@drawable/ic_launcher" android:label= "@ String/app_name " android:theme=" @style/apptheme "> <activity android:name=" Za.co.helloworld.LoginActivity " android:label=" @string/app_name "> <intent-filter> < Action android:name= "Android.intent.action.MAIN"/> <category android:name= " Android.intent.category.LAUNCHER "/> </intent-filter> </activity> </ Application>
When we create and run our own applications in the simulator, we should first see the display as shown. This means that we have successfully replaced the original blank activity class with the Loginactivity class that we just created.
Android Studio Learning---Templates