Android Question Blank Activity when Loading

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

When my app loads (Main Activity) it shows a blank activity for approx. 0.5ms and then the layout loads.

My layout doesn't have much on it, other than a few EditText boxes and a few labels.

I have my manifest with the following:

B4X:
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo.Light.NoActionBar")

By adding that last line it made it hide the title bar (which is what I want).

in my Activity_Create sub (the first line in that sub) I have:

B4X:
Activity.Color = Colors.RGB(0,85,167)

Which should set the activity back colour to a blue colour.

However, when my app loads it shows a light grey background and not a blue background while the app loads the layout.

Is there something I have done wrong ?
 

Peter Simpson

Expert
Licensed User
Longtime User
Try the following manifest code, it might help you out, change #435054 to suit.

B4X:
SetApplicationAttribute(android:theme, "@style/LightTheme")
    CreateResource(values, theme.xml,
        <resources>
            <color name="clr">#435054</color>
            <style name="LightTheme" parent="@android:style/Theme.Material.Light">
            <item name="android:windowBackground">@color/clr
            </item></style>
        </resources>
)

Enjoy...
 
Last edited:
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
What are you doind else in your activity_create which may causes the 0,5 sec delay?
Just the one layout. I am loading the layout into a Side menu (using ClsSlidingSidebar).

does the following code help at all, I think that it might help you.
I just tried that, but it shows the background to be a dark grey and the title bar is now showing.

Once the app has been open, and I press the home button and then open the app again, it shows the app fine. I guess it's because the app has loaded the layout already.

I might just leave it as it is.. I guess it's not a major thing but would of been good to solve.
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
I just tried that, but it shows the background to be a dark grey and the title bar is now showing

I had the same problem with the background loading white instead of grey in my case, the code I posted fixed the background color issue for me, the quick white background flash was seriously annoying me. Try playing about with it until it works perfect for you...
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
Try playing about with it until it works perfect for you
Just tried again by changing that colour value and it looks good now

B4X:
SetApplicationAttribute(android:theme, "@style/LightTheme")
    CreateResource(values, theme.xml,
        <resources>
            <color name="clr">#0055A7</color>
            <style name="LightTheme" parent="@android:style/Theme.Holo.Light.NoActionBar">
            <item name="android:windowBackground">@color/clr
            </item></style>
        </resources>
)

I wonder if there was a way in displaying a small image as well in the centre of the screen while it loads the layout?

I know I could load a layout with a image, but is there a way in doing that from the manifest so I don't have to wait for the layout to load? I guess I am going to have the same result as it needs time to load the image.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…