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.
Related
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.
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.
The main problem is the splash screen appears after 2-3 seconds. Before splash screen a blank layout appears which I don't want. Otherwise it runs fine. Just want to remove the blank layout which appears before the splash page.
MainActivity:
public class MainActivity extends Activity {
private static String TAG = MainActivity.class.getName();
private static long SLEEP_TIME = 5; // Sleep for some time
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE); // Removes title bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // Removes notification bar
setContentView(R.layout.activity_main);
// Start timer and launch main activity
IntentLauncher launcher = new IntentLauncher();
launcher.start();
}
private class IntentLauncher extends Thread {
#Override
/**
* Sleep for some time and than start new activity.
*/
public void run() {
try {
// Sleeping
Thread.sleep(SLEEP_TIME*1000);
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
// Start main activity
Intent intent = new Intent(MainActivity.this, Login.class);
MainActivity.this.startActivity(intent);
MainActivity.this.finish();
}
}
}
main layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#drawable/splash"
tools:context=".MainActivity" >
</RelativeLayout>
Generally speaking, splash screens are not recommended for an app but if you really must.
Android will load a blank layout before it loads an activity layout based on the theme you have set for it. The solution is to set the theme of the splash activity to a transparent one.
Create a transparent theme in res/values/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
Then set the theme in your manifest
<activity android:name=".SplashActivity" android:theme="#style/Theme.Transparent">
...
</activity>
It's better to use a Themed background for your starting activity but if you don't want the blank screen appears before launching main activity you can define your activity like this:
Add android:windowDisablePreview to your AppTheme in res/values/styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme">
<item name="android:windowDisablePreview">true</item>
</style>
</resources>
Then set your activity theme in your manifest:
<activity android:name=".MainActivity" android:theme="#style/AppTheme">
...
</activity>
P.S: Setting android:windowDisablePreview has no effect on your activity background, so you have nothing to worry about.
The problem you are facing here is called 'cold start' and it's the time mostly spent in your Application.onCreate method, which usually does some initialisations and it might take longer than you wish. You can read here the official documentation: https://developer.android.com/topic/performance/launch-time.html
If this is the case than setting the theme to translucent or disabling preview as others suggested will only apparently solve the issue, because in reality you will try to launch the app and you won't receive any feedback about the fact the you tapped the app icon. You will see your app starting with a delay, which is not a desired UX.
Blank, black or white screen, it really depends on the android:windowBackground attribute specified in your main activity theme.
The best you can do, apart from moving some of the initialisations that you probably are doing in your Application.onCreate method, is to brand your preview window with a logo as suggested in this post:
https://plus.google.com/+AndroidDevelopers/posts/Z1Wwainpjhd
You can go further and improve the user experience by animating your logo image in a splash screen, if it's the case, or by designing the preview window in a way that can be smooth transitioned to your main activity content, like described here:
http://saulmm.github.io/avoding-android-cold-starts
Same question is answered correctly here: https://stackoverflow.com/a/40482549/7094200 and described in this blog post: https://www.bignerdranch.com/blog/splash-screens-the-right-way/
With support for AppCompatActivity
res/values/styles.xml
<style name="SplashTheme" parent="AppTheme">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:windowDisablePreview">true</item>
</style>
GL
Source
Really! the below link work for me!!!!
https://cyrilmottier.com/2013/01/23/android-app-launching-made-gorgeous/
write the separate style in style.xml for your splash screen so that you can co-relate both the screen.
Herein the style:
<style name="AppTheme.Splash" parent="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowBackground">#drawable/splash_final</item>
</style>
It' s android features. You can change background color of your blankscreen. Use style:
<resources>
<style name="Theme" parent="android:style/Theme" />
<style name="Theme.MainTheme" parent="Theme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#drawable/background_drawable</item>
</style>
</resources>
then use it in manifest:
<application
android:name="#string/app_name"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.MainTheme"
>
I think this is similar to some answers that have been posted above. I still would like to recommend the following Big Nerd Ranch guide on how to create a splash screen the right way because its well illustrated and easy to follow. You should really go there and read it instead of continuing below :).
https://www.bignerdranch.com/blog/splash-screens-the-right-way/
But in short what it suggests is, at app start you launch an initial splash activity. For this activity you create an XML drawable (#drawable/background_splash).
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/gray"/>
<item>
<bitmap
android:gravity="center"
android:src="#mipmap/ic_launcher"/>
</item>
</layer-list>
Then you create a theme for splash activity’s and set the drawable you created above as its window background.
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/background_splash</item>
</style>
And then in the manifest you tell the splash activity to use the above theme.
<activity
android:name=".SplashActivity"
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 your splash activity implement theonCreate method like below (thats all the code you need in the activity). This will launch your main activity and finish the splash activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
Add this in your styles file
<item name="android:windowDisablePreview">true</item>
I fixed mine by just updating the build tools in Android Studio.
Add this style
<style name="Theme.Transparent" parent="AppTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDisablePreview">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
If you load image in your splash screen than load Image from your layout,
like below code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/color_white">
<ImageView
android:id="#+id/ivSplash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/SPLASH_IMAGE"
/>
</LinearLayout>
Sinle line solution. working perfect in my case;
just add this line in your app theme -
<item name="android:windowBackground">#drawable/splash</item>
I have a RelativeLayout with a background set with android:background="#drawable/background".
In my RelativeLayout` I have a standard button but when I run the app in devices running 3.1 or higher the button are displayed transparent.
I have tried setting android:alpha to 1 with no luck.
I know I can make a custom background with selector and shapes but there has to be another way.
Anyone else had this problem?
You'll want to add something like this to your style.xml
Application theme
<style name="ApplicationStyle" parent="android:Theme">
<item name="android:buttonStyle">#style/MyButtons</item>
</style>
Button style
<style name="MyButtons" parent="#android:style/Widget.Button">
<item name="android:textSize">16sp</item>
<item name="android:background">#000000</item>
</style>
Make sure you're setting your theme correctly in the manifest also
<application
android:allowBackup="true"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:theme="#style/Theme.ApplicationStyle" >
When I click the app icons and start to run the apps, it will appear a white screen for 1 sec.
I don't know why.
Is there any idea to clear this white screen and directly go to my activity?
The white/black screen is the window background image.
The window background is shown while e.g. your onCreate() runs and your layouts are being inflated. It can take some time especially if there's a lot of bitmaps that need to be read, decoded and scaled.
Changing the theme works because some themes have a non-default window background. For example, Theme.Wallpaper has a transparent background. There are other definitions there, too. Essentially what you want is:
<style name="YourTheme">
<item name="android:windowBackground">#null</item>
</style>
Programmatically you can achieve the same with
getWindow().setBackgroundDrawable(null);
at the top of activity onCreate().
(Old question but got bumped up by another answer and there wasn't a good answer.)
Settings. File>Settings>Build,Deployment>Instant Run Deselect all options shown there.
and add below line in your style.xml
<item name="android:windowDisablePreview">true</item>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowDisablePreview">true</item>
</style>
apply changes in AndroidMainfest.xml
<application
android:theme="#style/AppTheme">
After I change style.xml:
<resources>
<style name="AppTheme" parent="android:Theme.Wallpaper" />
</resources>
it works!!
Thanks all
Add the following in the manifest file of the corresponding activity
android:launchMode="standard"
and remove android:label="#string/app_name" from the corresponding activity ,this actually helped me
In your manifest.xml file remove the line android:theme="#style/AppTheme" for your app. and check it again
Use this tag in your manifest:
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
In Styles add the following things
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowIsTranslucent">true</item>
Hope this will help you and its working for me