最近搭建了app的情况,现在借着之前搭建的情况(Android学习20 -- 手搓App2(Gradle)-CSDN博客),试着弄一个launcher。
* The key to making your app a launcher is to declare the correct intent filter in your `AndroidManifest.xml` file. This tells the Android system that your app is capable of acting as a launcher.
* Here's how your `AndroidManifest.xml` should look (specifically the `<activity>` tag for your
所以修改之后的AndroidManifest.xml是如许。
最核心的就是在intent filter内里的配置,重点就是这几行。
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
* **Explanation:** *
`<action android:name="android.intent.action.MAIN" />`: This is the standard action for the main entry point of an app. * `
<category android:name="android.intent.category.LAUNCHER" />`: This category indicates that this activity should be listed in the app launcher (the list of apps). * `
<category android:name="android.intent.category.HOME" />`: This is the crucial category that tells the system this activity can act as a home screen replacement. * `
<category android:name="android.intent.category.DEFAULT" />`: This category is often used with `HOME` to ensure your app is considered a valid home screen option. *
MainActivity.java。主界面上面就是一个按钮,点了之后会启动一个浏览器。
package com.example.simpleapp;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {