Landscape splash screen for Android in PhoneGap Build

前端 未结 3 2545
别跟我提以往
别跟我提以往 2021-02-20 16:36

What should I enter to config.xml or what should I do in general, to have PhoneGap Build application\'s splash screen displayed correctly on Android device in lands

3条回答
  •  难免孤独
    2021-02-20 17:02

    I'm not using PhoneGap Build, but I managed to fix this in a basic PhoneGap Android app.

    Let's say you have two different splash images - a landscape and a portrait version - and you want both of them to stretch to fill the available screen area.

    Put one in drawable and the other in drawable-land. (Or drawable-land-hdpi, drawable-land-xhdpi, etc., if you you have multiple sizes.)

    Next, make sure that you're managing config changes yourself in AndroidManifest.xml:

    
    
    

    Then put this in your main Activity class that extends DroidGap.java:

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    
        if (super.splashDialog != null) {
            ViewGroup rootView = (ViewGroup) super.splashDialog.getWindow()
                    .getDecorView().findViewById(android.R.id.content);
            LinearLayout linearLayout = (LinearLayout) rootView.getChildAt(0);
            // manually refresh the splash image
            linearLayout.setBackgroundDrawable(null);
            linearLayout.setBackgroundResource(R.drawable.mysplash);
        }
    }
    

    This will cause the background image to redraw and properly stretch whenever the user changes orientation.

提交回复
热议问题