您的位置:首页 > 移动开发

android设置启动splash图片(消除启动白屏)不使用Appcompat主题设置的方法

2017-07-25 14:39 721 查看
至于使用Appcompat包的情况下,看另外一篇文章。 http://blog.csdn.net/robert_cysy/article/details/72824513
设置方法:
一、设置AndroidManifest,配置application 主题,和Activity主题

<application
android:name=".Application"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:screenOrientation="portrait"
android:theme="@style/NoTitleFullscreen2">

<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:launchMode="singleTask"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:theme="@style/NoTitleFullscreen2">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
二、编辑使用到的主题:

路径为:res/values/styles.xml

其中bg_splash是一张全屏的启动图片,在这里设置的图片,在点击app图标的那一刻就会加载。因此去掉白屏或黑屏,原理:这个图片替换了相当于原来白屏或黑屏的位置

<!--设置-全屏-->
<style name="NoTitleFullscreen2" parent="android:Theme.DeviceDefault.Light">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowBackground">@drawable/bg_splash</item>
</style>
三、使用这些达到了全屏的效果,然后真的进入Activity的时候,需要关闭全屏,以显示状态栏,和软件内容,通过俩个函数实现
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setWindowStatusBarColor(this , R.color.white);
cancelFullScreen(this );
}

public static void cancelFullScreen(Activity activity) {
activity.getWindow().clearFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

public static void setWindowStatusBarColor(Activity activity, int colorResId) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = activity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(activity.getResources().getColor(colorResId));

//底部导航栏
//window.setNavigationBarColor(activity.getResources().getColor(colorResId));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐