Set the original background color before upload

How to set background color for activity before setContentView

. I have an activity that takes a long time to load, I need to keep the color white until the activity completes loading.

+3


source to share


4 answers


I think this is exactly what you need.

First define the color in /colors.xml values

<resources>
    <color name="background">#FFFFFF </color>
</resources>

      

Create a themes.xml file in res / values ​​that references this color:



<resources>
 <style name="MyTheme" parent="@android:style/Theme.Light"> 
  <item name="android:windowBackground">@color/background</item>
 </style>
</resources>

      

... and then in your AndroidManifest.xml, specify this as the theme for your activity.

<activity
        android:name=".MyActivity"
        android:theme="@style/MyTheme" />

      

+4


source


You can do one of the following:

setContentView

can be called multiple times in the activity lifecycle. This way, you can simply set another layout file that only shows the background as you wish, and once you're done loading, call again setContentView

to load the actual layout!



OR

You can just manage all of this in one layout file by giving your root view a white background color than needed to show / hide the required section!

+1


source


In your oncreate add the following

Spinner = (ProgressBar) findViewById(R.id.LoginPageProgressBar);
    Spinner.setVisibility(View.GONE);

      

and when you click the button add the following before using intent

Spinner.setVisibility(View.VISIBLE);

      

0


source


From the documentation

setContentView (int layoutResID)

Set the content of the activity from the layout resource. The resource will be overestimated, adding all kinds of top level to the activity.

So the background color before setContentView()

impossible,

But try

  • Avoid too much code in onCreate()

    Activity

    .

  • Use AsyncTask

    to load data and display to progressbar

    user

  • Or you can implement some splash screen

    before loading the main one Activity

    .

0


source







All Articles