My background image is a PNG 375 × 667
Note that i'm NOT using setContentView() in my activity's onCreate()
I'm purely making use of a theme
Using a normal activity layout, user will see a blank dark screen for 2-3 seconds before they can see the Splash screen image the 1st time they launch the app ==> not what I want
I need the Splash screen image to show up immediately when user opens the app
Some people make the Splash screen transparent which means user will see nothing happens for 2-3 seconds the first time ==> unacceptable for me
Manifest.xml
<activity
android:name=".views.activities.SplashActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:launchMode="singleInstance"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
styles.xml
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:background">#drawable/bg_splash</item>
</style>
bg_splash.xml
<item
android:drawable="#android:color/black"/>
<item
android:drawable="#drawable/splash_full_tiny"
android:gravity="center">
</item>
This only happens a few devices:
Vodafone Smart ultra 6
A1601 (Oppo)
SM-A800I (Samsung)
try add this android:largeHeap="true"
<application
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:largeHeap="true"
></application>
Try to apply your SplashTheme style in application tag or you can add background to appTheme same as splashtheme. This will show your splash image quickly. Make sure once implemented check all activities. because it will used as background in your application. In all activities which have transparent background it will shows it as backgroud. I hope this may help you.
For this you should use different Images for different devices or any small image.
Related
I am currently trying to go full-screen during my splash-screen Activity. I am doing that with a style, which is set on the Activity like this:
style.xml
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#drawable/background_splash</item>
</style>
AndroidManifest.xml
<activity
android:name=".Activities.SplashScreenActivity"
android:noHistory="true"
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>
You might suggest doing that programmatically, but I already tried all the answers from this, this, this, this, this and this link. Currently, none of the programmatic solutions work for me - put every suggested fix in either onResume or onCreate of my splashActivity.java, but the status and navigation bar were still visible. However, when using my custom style it hides only the status bar, the navigation bar stays visible. What I've tried so far in the xml files: used different parents of the style, used no background drawable, removed screenOrientation and noHistory from activity. I am pretty sure I'm missing something here, but I can't see what. Can share more code if needed. Thanks in advance!
Here my SplashScreenActivity style:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/splash_logo_drawable</item>
</style>
I only use the attribute windowBackground
I've been searching online for the right way to avoid the white screen - replacing it with a splashscreen - when my Android app launches.
I found solutions that uses styles like
<style name="AppTheme.SplashTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowIsTranslucent">true</item>
</style>
But in my case this only delays the view appearance, acting as the app doesn't work (the view inflates after a couple of seconds). I do not want some view that lasts for some seconds I've decided, I just want to replace the blank screen to something custom while my app needs to load.
The only way to have the desired behaviour was to place a drawable as a background in the style of my SplashscreenActivity.
<item name="android:windowBackground">#drawable/background_splash</item>
Now, I would like not to place an image as a background-because of the different resolutions of screens- but to set an xml layout.
Is this possible? What's the best way to get rid of the blank screen without delaying the view appearance?
You should do it as follows
create an xml file in res/drawable folder with below content. This will act as your splash screen. Let's name it splash.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/colorPrimary" />
<item>
<bitmap android:src="#drawable/splash_logo"
android:gravity="center" />
</item>
</layer-list>
Then you need to specify a style/theme without titlebar for your splash view, so add below style to your style.xml file.
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/splash</item>
</style>
In AndroidManifest.xml change theme of your launcher activity to use SplashTheme
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Finally in that launcher activity (in my example MainActivity) change the theme back to default application theme, usually named AppTheme
#Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppTheme)
super.onCreate(savedInstanceState);
...
}
That's it! Now run your application and see that there is no white screen anymore.
References: I used this post and this one to provide the above code example.
How can I make my application have the same background everywhere? I've tried to do it with editing the theme but the problem there was that my app uses an animation in which, when you go to an new layout it slides over. So want I want is a way to have the same background everywhere and when a new layout slides in only textviews and buttons and sh*t should move. The background has to stand still at the same position.
Also, what is the best size for an background within an app? 1080x1920 is a bit slow :P
THANKS!!
What i've tried: (values/styles.xml)
<resources>
<!-- Base application theme. -->
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="#style/Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:background">#drawable/background</item>
</style>
(androidmanifest)
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.Light.NoActionBar.FullScreen" >
// unimportant things here
</application>
You can just set the background you need in the config file. Once you've done that, simple make sure you don't set the background anywhere else and you should be okay.
I've used the following style:
http://jgilfelt.github.io/android-actionbarstylegenerator/#name=zhc_style&compat=appcompat&theme=light_dark&actionbarstyle=solid&texture=1&hairline=1&neutralPressed=1&backColor=cd0079%2C100&secondaryColor=cd0079%2C100&tabColor=cd0079%2C100&tertiaryColor=303030%2C100&accentColor=cd0079%2C100&cabBackColor=002E3E%2C100&cabHighlightColor=cd0079%2C100
Long story short, it makes the ActionBar purple.
I've taken all the files from the .zip file and placed them in my project. Within the <resources> of the file styles_zhc_style.xml I've got:
<style name="Theme.Zhc_style" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarItemBackground">#drawable/selectable_background_zhc_style</item>
<item name="android:popupMenuStyle">#style/PopupMenu.Zhc_style</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.Zhc_style</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle.Zhc_style</item>
<item name="android:actionDropDownStyle">#style/DropDownNav.Zhc_style</item>
<item name="android:actionBarStyle">#style/ActionBar.Solid.Zhc_style</item>
<item name="android:actionModeBackground">#drawable/cab_background_top_zhc_style</item>
<item name="android:actionModeSplitBackground">#drawable/cab_background_bottom_zhc_style</item>
<item name="android:actionModeCloseButtonStyle">#style/ActionButton.CloseMode.Zhc_style</item>
<!-- Light.DarkActionBar specific -->
<item name="android:actionBarWidgetTheme">#style/Theme.Zhc_style.Widget</item>
</style>
I've changed my Android Manifest to the following:
<application
android:allowBackup="true"
android:name="com.zhc.android.ZHCApp"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Zhc_style" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
My minimum sdk version is 16, my target sdk version is 21.
I still get the dark ActionBar on top of my application. When I change the settings using the Style Generator to have the Base Theme 'Light' and move all the files again, I see that the ActionBar indeed becomes light themed. Lighter ActionBar, black instead of white letters... but still no purple.
What am I doing wrong?
I've 'solved' the problem by removing the NavigationDrawer Fragment I've used, and placed a Toolbar on top instead. (Android 5.0).
Not really a solution, but an alternative people could consider.
hey i want a default screen when my android activity is loading...usually it creates a fully black background effect..that may confuse users..
so i try this code
create a file inside res/values/theme.xml
then put this code..
<resources>
<style name="Theme.MyAppTheme" parent="android:style/Theme" >
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#drawable/bid_screen_preparing</item>
</style>
</resources>
I also added this file in manifest file like
<application
android:allowBackup="true"
android:allowClearUserData="true"
android:icon="#drawable/bid_icon"
android:label="#string/app_name"
android:logo="#drawable/bid_logo"
android:theme="#style/Theme.MyAppTheme" > ........
It works only when i press back button and activity back to his previous one..But when i load one activity to another then it asusual shows the black color...dont know why..
please change these line
<resources>
<style name="Theme.MyAppTheme" parent="android:style/Theme" >
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#drawable/bid_screen_preparing</item>
</style>
</resources>
and use these lines
<resources>
<style name="MyAppTheme" parent="android:style/Theme.light" >
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#drawable/bid_screen_preparing</item>
</style>
</resources>
and remove these lines
<application
android:allowBackup="true"
android:allowClearUserData="true"
android:icon="#drawable/bid_icon"
android:label="#string/app_name"
android:logo="#drawable/bid_logo"
android:theme="#style/Theme.MyAppTheme" > ........
to
<application
android:allowBackup="true"
android:allowClearUserData="true"
android:icon="#drawable/bid_icon"
android:label="#string/app_name"
android:logo="#drawable/bid_logo"
android:theme="#style/MyAppTheme" > ........
It works only when i press back button and activity back to his previous one..But when i load one activity to another then it asusual shows the black color...dont know why..
This is how the system works - if you're just jumping from one activity to the next (like by calling startActivity() from onCreate(), the system won't bother drawing anything to prevent a flickering effect (this was explained by Dianne Hackborn a while back on the Android Developer forums).
If you're trying to implement a loading screen, you need to spawn off an AsyncTask that does the loading work off the main thread then starts the next activity when it's finished. Then your first activity will have time to draw the "loading" message.