Android T startingwindow使用总结

startingwindow介绍

startingwindow是什么

在activity真正显示之前,可能要处理大量耗时任务,如进程创建,资源加载,窗口绘制等。所以在窗口的过渡动画完成之后,可能应用还没有完成页面的绘制,我们需要一个页面来等待真正的activity显示,下面的图就是应用启动时所显示的纯色背景,和icon

StartingWindow使用总结的目的

本次文章的分享不会讲解StartingWindow的窗口的添加流程和移除流程,在网上其他博客总结分享的已经很充分了,这篇博客主要是分享我们如何定制这个StartingWindow,和系统侧是如何处理的

定制属性有那些

这些属性本文章不会讲解完,至于会设计到那些,主要看后面的补充了

windowSplashscreenContent

复制代码
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme.TestActivity03" parent="android:Theme.Material.Light.NoActionBar" >
        <item name="android:windowSplashscreenContent">@layout/activity_main</item>
    </style>
</resources>

这段代码大家一定不陌生吧,这是配置一个activty的主题的,在其中指定一个windowSplashscreenContent,告诉系统我们的开屏内容主要显示我们自己设置的,

我们来看看底层是如何实现的

peekLegacySplashscreenContent 这段代码主要是获取应用设置的windowSplashscreenContent获取对应的资源id,用来显示对应的getDrawable(),如下,这是我设置的启动的背景

windowSplashScreenAnimatedIcon

复制代码
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme.TestActivity03" parent="android:Theme.Material.Light.NoActionBar" >
        <item name="android:windowSplashscreenContent">@drawable/aa</item>
        <item name="android:windowSplashScreenAnimatedIcon">@drawable/aa</item>
    </style>
</resources>

这段代码新增了一个windowSplashScreenAnimatedIcon,设置显示的icon,我们先看看底层是如何实现的

在启动时,getWindowAttrs(context, mTmpAttrs);回去读取应用自己设置的所有属性,存给变量mSplashScreenIcon,

继续回到获取到的设置给iconDrawable = mTmpAttrs.mSplashScreenIcon;

复制代码
      private SplashScreenView fillViewWithIcon(int iconSize, @Nullable Drawable[] iconDrawable,
                Consumer<Runnable> uiThreadInitTask) {
            Drawable foreground = null;
            Drawable background = null;
            if (iconDrawable != null) {
                foreground = iconDrawable.length > 0 ? iconDrawable[0] : null;
                background = iconDrawable.length > 1 ? iconDrawable[1] : null;
            }

            Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "fillViewWithIcon");
            final ContextThemeWrapper wrapper = createViewContextWrapper(mContext);
            final SplashScreenView.Builder builder = new SplashScreenView.Builder(wrapper)
                    .setBackgroundColor(mThemeColor)
                    .setOverlayDrawable(mOverlayDrawable)
                    .setIconSize(iconSize)
                    .setIconBackground(background)
                    .setCenterViewDrawable(foreground)
                    .setUiThreadInitConsumer(uiThreadInitTask)
                    .setAllowHandleSolidColor(mAllowHandleSolidColor);

            if (mSuggestType == STARTING_WINDOW_TYPE_SPLASH_SCREEN
                    && mTmpAttrs.mBrandingImage != null) {
                builder.setBrandingDrawable(mTmpAttrs.mBrandingImage, mBrandingImageWidth,
                        mBrandingImageHeight);
            }
            final SplashScreenView splashScreenView = builder.build();
            Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
            return splashScreenView;
        }
    }

在后续流程中会创建一个SplashScreenView,并且吧回到的各种参数设置给SplashScreenView,如下

复制代码
    final SplashScreenView.Builder builder = new SplashScreenView.Builder(wrapper)
                    .setBackgroundColor(mThemeColor)
                    .setOverlayDrawable(mOverlayDrawable)
                    .setIconSize(iconSize)
                    .setIconBackground(background)
                    .setCenterViewDrawable(foreground)
                    .setUiThreadInitConsumer(uiThreadInitTask)
                    .setAllowHandleSolidColor(mAllowHandleSolidColor);

最后会把应用携带过来的参数设置给imageView.setBackground(mIconBackground);,显示对应的图标,

相关推荐
优雅的潮叭21 小时前
cud编程之 reduce
android·redis·缓存
2601_9496130221 小时前
flutter_for_openharmony家庭药箱管理app实战+用药知识详情实现
android·javascript·flutter
一起养小猫21 小时前
Flutter for OpenHarmony 实战 表单处理与验证完整指南
android·开发语言·前端·javascript·flutter·harmonyos
2601_9499750821 小时前
flutter_for_openharmony城市井盖地图app实战+附近井盖实现
android·flutter
倾云鹤21 小时前
通用Digest认证
android·digest
我是阿亮啊1 天前
Android 自定义 View 完全指南
android·自定义·自定义view·viewgroup
2601_949833391 天前
flutter_for_openharmony口腔护理app实战+意见反馈实现
android·javascript·flutter
峥嵘life1 天前
Android 16 EDLA测试STS模块
android·大数据·linux·学习
TheNextByte11 天前
如何打印Android手机联系人?
android·智能手机
泡泡以安1 天前
Android 逆向实战:从零突破某电商 App 登录接口全参数加密
android·爬虫·安卓逆向