Android splash screen is shrunk - android

I have trouble with android splash screen.
I made splashscreen like these
/platform/android/res/drawable-hdpi/background.9.png
/platform/android/res/drawable-mdpi/background.9.png
/platform/android/res/drawable-xhdpi/background.9.png
/platform/android/res/drawable-xxhpi/background.9.png
/platform/android/res/drawable-xxxhdpi/background.9.png
These are made by ticon automatically.
and have confirmed these looks OK(correct background.9 below).
However, when I open appication (on Nexus7 2013),splashscreen looks much smaller.
I mean background.9.png are centered and there are white blank around image.
correct background.9
shown splashscreen
How can I adjust it to the screen???

To adjust it to the screen, you just have to resize it accordingly and then create a drawable file like this for each screen size (this exemple will display a gradient background with an image in the center)
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#2b3143"
android:centerColor="#37465e"
android:endColor="#55647c"
android:angle="135"/>
</shape>
</item>
<item>
<bitmap
android:gravity="center"
android:src="#drawable/myCuteLogo"/>
</item>
You then create a style and set the property android:windowBackground with the drawable you created:
<style name="SplashScreenStyle" parent="myAppTheme">
<item name="android:windowBackground">#drawable/splash_screen</item>
</style>
Then create a SplashActivity that will display the Splash screen:
public class SplashScreen extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, Activity_a_Main.class);
startActivity(intent);
finish();
}}
Lastly in your manifest set the SplashActivity as the Lancher activity and set its theme to the style you created:
<activity android:name=".Activities.SplashScreen"
android:theme="#style/SplashScreenStyle">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I hope this helps you
NOTE: If you set the style you created as the whole application's theme, it will show your drawable in weird places, like in the background of a soft keyboard

Related

New Splash screen is shown cut in a cyrcle shape

I'm trying to replace my old activity based splash screen in my Android app with the new Splashscreens API
So i've created a svg of my app logo, create the theme, and set in my MainActivity the installSplashScreen but the logo in the Splashscreen looks like this when app is launched:
How could i fix that issue?
Here is what i've done style.xml:
<style name="Theme.App.Starting" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">#color/colorAccent</item>
<item name="windowSplashScreenAnimatedIcon">#drawable/ic_visual_vector</item>
<item name="postSplashScreenTheme">#style/AppTheme</item>
</style>
Manifest:
<activity
android:name=".MainActivity"
android:theme="#style/Theme.App.Starting"
android:screenOrientation="portrait"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
MainActivity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SplashScreen.installSplashScreen(this);
setContentView(R.layout.activity_main);
...
What you can do is to wrap your icon in an inset drawable so that it is drawn inside the circle.
For example, create a drawable/splash_inset.xml resource:
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/ic_visual_vector"
android:insetLeft="72dp"
android:insetRight="72dp"
android:insetTop="72dp"
android:insetBottom="72dp"/>
The actual inset values depend on your image and its aspect ratio, using 72dp here on all edges as an example.
Then apply this drawable as your windowSplashScreenAnimatedIcon.
In Android 12, if your icon is bigger than the required size, it'll be cut off.
App icon without an icon background: This should be 288×288 dp, and fit within a circle of 192 dp in diameter.
For example, if the full size of an image is 300×300 dp, the icon needs to fit within a circle with a diameter of 200 dp. Everything outside the circle will be invisible (masked).
More info: https://developer.android.com/guide/topics/ui/splash-screen#elements
My answer could be late but I had same issue. I only added android:gravity="center" to my drawable/splash_logo.xml file and using the splash_logo.xml in styles.xml file.
<layer-list>
<item android:gravity="center"
android:src="#drawable/splash_logo_icon" />
This happens when I run my app on an emulator 30s but when I run it on a physical device it show well. Looking at your code and comment above, is it really required you implement the image from the styles/Res ?... I recommend you create the imageView in your splash_screen.xml

Splash screen showing on the background of main activity

I've set a splash screen on my app using this guide.
The background of my app is a transition color (changing color every few seconds using animation-list.
After the splash screen is shown (at the startup of the app), it stays in the background of the main activity.
screenshot
This is spalsh_screen.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#android:color/white"/>
<item>
<bitmap
android:src="#drawable/talki_logo_big"
android:gravity="center"/>
</item>
</layer-list>
This is the animation_list.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:visible="true">
<item
android:drawable="#drawable/gradient_background_1"
android:duration="2500" />
<item
android:drawable="#drawable/gradient_background_2"
android:duration="2500" />
<item
android:drawable="#drawable/gradient_background_3"
android:duration="2500" />
<item
android:drawable="#drawable/gradient_background_4"
android:duration="2500" />
<item
android:drawable="#drawable/gradient_background_5"
android:duration="2500" />
</animation-list>
Is there a way to make the splash screen disappear?
Thanks! :)
The solution is already there in the tutorial you linked.
The easiest way to transition back to your normal theme is to call
setTheme(R.style.AppTheme) before super.onCreate() and
setContentView().
public class MyMainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// Make sure this is before calling super.onCreate
setTheme(R.style.Theme_MyApp);
super.onCreate(savedInstanceState);
// ...
}
}
Reason of Fail
You have set AppTheme.Launcher in manifest, which gives a background to Activity. Now after Activity is started, you need to change that theme to your App theme to remove the Splash Background.
Try to add the property android:noHistory="true" in the manifest for your splashscreen activity.
A value of "true" means that the activity will not leave a historical trace. It will not remain in the activity stack for the task, so the user will not be able to return to it and maybe it won't show in the background.

Qt Quick Controls 2 Splash Screen

I am developing a mobile app using Qt Quick Controls 2, and would like to display a splash screen while the app is being initialised. Currently, this is what the user sees when the app is started:
A dark background with the name of the app as a header.
A blank, white background.
The application window.
In that order for an Android 6 Marshmallow smartphone. If I add the splash screen to the application window, perhaps in a stack view, and then transition to the actual contents when it is initialised, (1) and (2) would still remain, right? Is there any way to tell Qt to display the splash screen instead of (1) and (2), or at least instead of (1)?
First in _yourProject_/android/res/drawable create a splash.xml file:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" >
<solid android:color="#353535"/>
</shape>
</item>
<item>
<bitmap android:src="#drawable/icon" android:gravity="center" />
</item>
</layer-list>
That sets the splash screen background color and icon that will be centered on the screen.
Then in /android/res/values create a theme.xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="#android:style/Theme.DeviceDefault.Light.NoActionBar">
<item name="android:windowBackground">#drawable/splash</item>
</style>
</resources>
Then in the android manifest file, on the line <activity android:configChanges= add android:theme="#style/AppTheme" after the label settings, then scroll down to the <!-- Splash screen --> section and uncomment and modify the line:
<meta-data android:name="android.app.splash_screen_drawable" android:resource="#drawable/splash"/>
Replace the #353535 color with whatever the color of your application window is set to for smooth transition. The image is optional.
I just tested that and it works. Perhaps someone else will be able to provide a solution for iOS.

Override activity's background that was set by theme

I currently have an Activity for my splash screen. The following is the way I apply a theme to the activity:
<application
...
<activity
android:name=".activities.SplashActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
SplashTheme is defined as follows:
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:background">#drawable/splash_background</item>
</style>
splash_backround.xml is defined as follows:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap
android:src="#drawable/login_background"
android:tileMode="disabled" />
</item>
<item>
<bitmap
android:src="#drawable/login_siren"
android:tileMode="disabled"
android:gravity="bottom|center_horizontal" />
</item>
<item android:top="120dp">
<bitmap
android:src="#drawable/splash_welcome"
android:tileMode="disabled"
android:gravity="top|center_horizontal" />
</item>
I am not calling setContentView() in onCreate() of my SplashActivity class, so thing being displayed is what is set by the SplashTheme.
A situation has come up where I want to display an AlertDialog if something fails to load upon Application.onCreate(). The splash screen is displaying at the time I use this to build, create and show the AlertDialog. However, when I show the AlertDialog, it gets assigned the background from the Activity's theme. Even if I define a custom style for the AlertDialog (via android:alertDialogTheme or android:alertDialogStyle) that explicitly defines a different background, it gets overruled by the background defined by the activity. As a result, I've changed SplashTheme to the following:
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/splash_background</item>
</style>
This now releases control of the alert dialog background as I am not explicitly setting android:background in my Activity theme. However, the window background does not account for the status bar (i.e. the background applies underneath the status bar as well). As a result, I get a bit of jump when the splash screen transitions to the next activity that uses this same background in its layout (due to accounting for the status bar). So, this solution still isn't working as I'd like.
If I do use the original SplashTheme (where I define android:background), is there a way to override the theme's defined android:background for an AlertDialog?
It is not possible to change a theme of activity once it is applied.
Is there a way to override the theme's defined android:background for an AlertDialog?
AlertDialog has a constructor, which accepts themeResId as an input. From docs of AlertDialog (Context context, int themeResId):
Creates an alert dialog that uses an explicit theme resource.
Create a custom theme, overriding android:background attribute, then create AlertDialog using newly created theme:
Dialog dialog = new AlertDialog(context, R.style.my_dialog_theme);

Launcher activity setContentView delay

I created a simple app with Splash screen which is shown for 1 second. Splash screen is almost red. But I noticed that when I launch my app at first for ~0.3 sec appears white screen and after that appears my Splash screen. Is it possible to remove this white screen or make it predefined red? I testes it on nexus 4 with android 5.0, and my Splash activity have quite simple implementation, and nothing can delay onCreate():
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
waitTask = new WaitTask();
waitTask.execute();
}
private class WaitTask extends AsyncTask<Void, Integer, Void> {
#Override
protected Void doInBackground(Void... params) {
try {
TimeUnit.MILLISECONDS.sleep(SPLASH_DURATION);
} catch (InterruptedException e) {
// Do nothing
}
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
Intent intent = new Intent(LauncherActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
}
I have noticed that almost all apps show it first screen with some delay and this white screen, but in some app this screen is back. Is there any way to control it?
You can define the style of the activity and set it in the Manifest. This way, when the activity runs, it will use its pre defined style (in which you will have the background or windowBackground set to red) and within that 0.3 seconds, the windows will still be red.
Define the colour:
<resources>
<color name="background">#FF0000</color>
</resources>
Then define the style:
<resources>
<style name="MyLaunchActivityTheme" parent="#android:style/Theme.Light">
<item name="android:windowBackground">#color/background</item>
</style>
</resources>
Then set the style for the activity in the manifest:
<activity
android:name=".MyActivity"
android:theme="#style/MyLaunchActivityTheme"/>
The ans Sam gave is perfect but to extend it - let you want to have your custom splash screen image visible for the whole time, If we apply color to the window then there will be a switch from color to the actual slash screen. The ans which i propose dont require setContentView but only manage splash screen through theme.
We can't set the theme in java as in my case the control came to onCreate of my splash activity very late. Till that time black screen keep visible.
This gave me clue that window has to be managed from theme which we specify in manifest.
There is the manifest i have:
<activity
android:name=".main.activities.SplashScreen"
android:theme="#style/Splash"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Now The theme i created is as follows:
<style name="Splash" parent="#style/Theme.AppCompat.Light">
<item name="android:windowBackground">#drawable/splash</item>
<item name="android:windowNoTitle">true</item>
<item name="windowNoTitle">true</item>
<item name="colorPrimaryDark">#color/green_09</item>
<item name="colorPrimary">#color/green_09</item>
<item name="windowActionBar">false</item>
</style>
Splash in the drawable resource which contains a bitmap resource, I have to tweak a bit to make it look perfect not stretched and in center:
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:antialias="true"
android:dither="true"
android:gravity="fill"
android:src="#drawable/splash_screen" />

Categories

Resources