#Android application interface development

Chapter 1 Learning

#### Part 2 ####


1. Create an Android app

Name your project FirstAty and name your XML file activity_first_aty.

Open activity_first_aty. XML file and add a line android:gravity=”center_horizontal” textView as follows:

<?xml version="1.0" encoding="utf-8"? >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 android:gravity="center_horizontal"
 tools:context="comeinsteinford.github.firstapplication.FirstAty">

 <TextView
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="@string/text01"
 android:textSize="36sp"
 android:id="@+id/tvHello" 
 />
</RelativeLayout>
Copy the code

@String/Text01 will get an error, left-click on the red word, pop up the red light bulb, click on the menu, select the first one, create a String Resource in the Resource Value, fill in the text you want to appear in the TextView.

As shown above, a line of text at the top of the center appears in the app.


2. Create a home page that disappears automatically after the App is started

Create a new Activity, call it StarAty, and the XML will be automatically named. First, I wanted the home page to be full screen, so modify staraty. Java as follows

public class StarAty extends Activity {
 Handler mHandler = new Handler();

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 this.requestWindowFeature(Window.FEATURE_NO_TITLE); // Hide the title bar, inherited from the Activity
 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); 
 // Hide status bar
 setContentView(R.layout.activity_star_aty);
 mHandler.postDelayed(new Runnable() {
 @Override
 public void run(a) {
 Intent intent = new Intent(StarAty.this, MainActivity.class);
 //intent indicates an intentstartActivity(intent); }},2000); // Set the page to jump after 2 seconds}}Copy the code

Of course, the XML file should also be modified to beautify the AD page

<?xml version="1.0" encoding="utf-8"? >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 android:background="#0099cc"
 tools:context="comeinsteinford.github.myapplication001.StarAty">

 <TextView
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:text="@string/starWord"
 android:id="@+id/tvStart"
 android:gravity="center"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:textSize="50sp"
 android:textStyle="bold"/>
Copy the code

Again, search ADB Idea using the Plugins Repositories Repositories File >Settings >Plugins >Browse Repositories in Android Studio, install, and restart

This plug-in provides the following features: ADB Kill App ADB Start App ADB Restart App ADB Clear App Data ADB Clear App Data and Restart: Clears application Data and restarts the application

In the code interface, use CTR + Shift +A to activate the search function. Search more Adb to use the above function.