在 Android 12 的 Beta 版本中,官方提供了 Splash Screen 功能,但没有提供修改方法。为了自定义 Splash Screen,可以使用以下代码示例:
1.在 app 的 res/drawable 文件夹中创建一个新的文件,例如 splash_background.xml,并将以下代码添加到文件中:
2.在 app 的 styles.xml 文件中添加以下样式代码:
3.在 app 的 AndroidManifest.xml 文件中,将 SplashActivity 的主题设置为刚才创建的样式:
4.创建一个新的 SplashActivity,并将它设置为应用程序的启动活动:
public class SplashActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = new Intent(this, MainActivity.class); startActivity(intent); finish(); } }
这样就可以在 Android 12 的 Beta 版本中自定义 Splash Screen 了。