向 Google 的新启动画面模式添加进度指示器

Adding a progress indicator to Google's new Splashscreen pattern

浏览此博客 post Splash Screens the Right Way 后,我发现了 Google 创建闪屏的新方法。

但我对这种新方法的问题是在初始屏幕上添加了一个进度 bar/indicator。

我找到了几个解决方案,但它们都是自定义 xml 布局而不是 Drawables

我也尝试在我的 Background_splash.xml 中创建一个进度对话框,该对话框位于我的可绘制文件夹中,但我收到一个错误消息,说它是不允许的。

我的应用程序从初始屏幕开始,到应用程序介绍 activity,然后到主屏幕 activity。

有什么方法可以在这种类型的闪屏上添加进度 indicator/bar 吗?

下面是我使用 启动画面的正确方式 教程

创建的代码

Background_splash.xml

<?xml version="1.0" encoding="utf-8"?>

<item
    android:drawable="@color/grey"/>

<item>
    <bitmap
        android:gravity="center"
        android:src="@mipmap/ic_launcher"/>

</item>

AndroidManifest.xml

    <activity
        android:name="com.domain.app.appintro.SplashActivity"
        android:theme="@style/SplashTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

Styles.xml

 <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/background_splash</item>
</style>

您是否考虑过使用 AsyncTask 来加载 progressDialog。您可能试图在主线程中下载一些东西,这会阻止启动画面加载。

public class MyActivity extends Activity {
private ProgressDialog pd = null;
private Object data = null;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Show the ProgressDialog on this thread
        this.pd = ProgressDialog.show(this, "Working..", "Downloading Data...", true, false);

        // Start a new thread that will download all the data
        new DownloadTask().execute("Any parameters my download task needs here");
}

    private class DownloadTask extends AsyncTask<String, Void, Object> {
         protected Object doInBackground(String... args) {
         Log.i("MyApp", "Background thread starting");

         // This is where you would do all the work of downloading your data

         return "replace this with your data object";
     }

     protected void onPostExecute(Object result) {
         // Pass the result data back to the main activity
         MyActivity.this.data = result;

         if (MyActivity.this.pd != null) {
             MyActivity.this.pd.dismiss();
         }
     }
}    

}

以此为起点并将其作为您的 mainActivity 的内部 class。

答案是你不能!如果你想在应用程序加载之前显示启动画面,通过主题,它必须是静态图像。
如果你想在应用加载后显示一个进度条,例如,如果你需要下载数据,那么你可以添加一个进度条到 splash activity,它将在静态图像之后显示应用程序完成加载。
如果您不需要在应用加载后等待,那么您只是在浪费用户时间,增加另一个等待时间,并使应用变得糟糕。
所有这些都可以从您链接的文章的评论和回复中理解。

正如@lionscribe 所说的那样,无法使用这种方法创建自定义启动画面。但是,这 http://saulmm.github.io/avoding-android-cold-starts 可能会帮助那些希望在新的闪屏方法中为元素设置动画的人。