android应用启动时默认会有黑屏/白屏的闪过,这是由于View加载时会先加载DectorView,然后由外层View向内层View逐层加载, 大概ViewGroup ->view -> subview...而每个View都会占有一块相应的矩形的区域,这样View是有背景的,因此会有黑屏/白屏的闪 现,解决思路: 今早加载启动页面背景,不加载View背景就会避免该现象; 《一》,通过设置主题来提前加载:当我们建立项目时习惯自定义一个Theme,在Manifest.xml文件中声明使用:
<application android:name=".application.BaseApplication" android:hardwareAccelerated="true" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/app_theme" ...> “ 在建立自定义主题时我们要注意,如果Activity我们继承的AppCampatActivity时,Parent 主题样式一定是 Theme.AppCampat.系列的主题,否则报错 ” 自定义Style:<resources> <!--app 主题 no ActionBar--> <style name="app_them" parent="Theme.AppCompat.Light.NoActionBar"> <!--默认所有window设置全屏模式--> <item name="android:windowFullscreen">true</item> <!--设置所有页面不为透明模式,开发半透明模式时使用该属性--> <item name="android:windowIsTranslucent">false</item> <!--默认所有window窗口背景设为透明无颜色--> <item name="android:windowBackground">@android:color/transparent</item> <!--动画样式--> <item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item> <!--window窗口设为无标题模式,默认windowFullscreen=true,此方法不生效--> <item name="android:windowNoTitle">true</item> </style> <style name="LauncherTheme" parent="app_them"> <item name="android:state_window_focused">false</item> <!--启动优化,不会产生白屏间隔快速显示背景--> <item name="android:windowBackground">@mipmap/bg_default</item> </style> </resources>
我们可以先创建一个基础样式,"name = base_theme",然后不同的页面fen别去扩展,parent="base_theme
";
《二》,通过代码在运行时加载:
同时我们还可以通过java代码去实现,如下:@Override protected void onCreate(Bundle savedInstanceState) { setTheme(R.style.app_them); super.onCreate(savedInstanceState);//去除TitlesetContentView(R.layout.activity_launcher); infoManager = InfoManager.getInstance();this.requestWindowFeature(Window.FEATURE_NO_TITLE); //设置满屏this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
xzcv