创建Android应用程序的具体步骤如下
(1)file-new project
(2)选择empty actity,next
(3)name,package name,路径,单击finlish
详细解MyFristApplication
MainActivity.java
package com.adou.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
// 创建MainActivity类集成自AppCompatActivity(界面类)
public class MainActivity extends AppCompatActivity {
// 重写AppCompatActivity的onCreate方法,将在页面创建时被调用
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 设置内容视图(R.layout.activity_main)
setContentView(R.layout.activity_main);
}
}
activity_main.xml
1、定义一个相对布局
2、定义一个子标签->TextView 文本控件,设置宽、高、文本内容
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.adou.myapplication">
<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>
</application>
</manifest>