用 Use legacy android.support libraries 建项目

2020-06-18 作者: 硬汉无敌

1、点击Start a new Android Studio project 创建新项目【图-1】。


【图-1】

2、选择“No Activity”,进入【图-2】,勾选“Use legacy android.support libraries”,设置Mininum SDK,注意最大只能选择到API 28,单击完成。

3、打开Module的build.gradle,如【图-3】,将compileSdkVersion 和 targetSdkVersion给为28.


【图-3】

4、添加activity,按【图-4】右键java包,然后在菜单中选择“Empty Activity”


【图-4】

5、【图-5】中的Launcher Activity 勾选上,这个Activity将被设置成default activity,如果没有default activity,系统会报Default Activity not found错误。这里不勾选,然后看怎么修改。


【图-5】

6、打开AndroidManifest.xml文件,在activity 中添加“intent-filter”设置默认Activity。

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3. package="com.example.myapplication">
  4. <application
  5. android:allowBackup="true"
  6. android:icon="@mipmap/ic_launcher"
  7. android:label="@string/app_name"
  8. android:roundIcon="@mipmap/ic_launcher_round"
  9. android:supportsRtl="true"
  10. android:theme="@style/AppTheme">
  11. <activity android:name=".MainActivity">
  12. <intent-filter>
  13. <action android:name="android.intent.action.MAIN" />
  14. <category android:name="android.intent.category.LAUNCHER" />
  15. </intent-filter>
  16. </activity>
  17. </application>
  18. </manifest>

7、编译运行效果如【图-6】。