cocos creator打包原生加背景图片,不然一开始会有黑屏的。

  1. 改AndroidManifest.xml文件

    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    ->
    android:theme="@style/ImageSplashStyle"
  2. 添加片背景主题

    <?xml version="1.0" encoding="utf-8"?>
    <resources >
     <style name="ImageSplashStyle"
            parent="@android:style/Theme.NoTitleBar.Fullscreen" >
         <item name="android:windowBackground" >@drawable/bg</item >
     </style >
    </resources >
  3. 放bg图片在drawable文件夹
  4. ts里面加hideNativeSplash,在场景价加载的时候发送

     hideNativeSplash() {
         if (cc.sys.os == cc.sys.OS_ANDROID && cc.sys.isNative) {
             jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "hideNativeSplash", "()V");
         } else if (cc.sys.os == cc.sys.OS_IOS && cc.sys.isNative) {
             jsb.reflection.callStaticMethod("AppHelper", "hideNativeSplash:", "");
         }
     }
  5. 改AppActivity.java

    private static ImageView sSplashBgImageView = null;
    onCreate函数调用showNativeSplash();
    加这2个函数
     private static void showNativeSplash() {
         sSplashBgImageView = new ImageView(sapp);
         sSplashBgImageView.setImageResource(R.drawable.bg);
         sSplashBgImageView.setScaleType(ImageView.ScaleType.FIT_XY);
         sapp.addContentView(sSplashBgImageView,
                 new WindowManager.LayoutParams(
                         FrameLayout.LayoutParams.MATCH_PARENT,
                         FrameLayout.LayoutParams.MATCH_PARENT
                 )
         );
     }
     public static void hideNativeSplash() {
         sapp.runOnUiThread(new Runnable() {
             @Override
             public void run() {
                 if (sSplashBgImageView != null) {
                     sSplashBgImageView.setVisibility(View.GONE);
                 }
             }
         });
     }

    搞定!

标签: none

添加新评论