Splashscreen like google apps - android

Most of google applications (e.g Google Maps, Google sheets, etc...) have a pretty nice splashscreen, that pops up very quickly.
It doesn't look like a "classic" Android splashscreen made of an Activity launching another one after xx secs.
It makes me think of the iOS equivalent (Launch images).
Is it a new UI element that we can use ? Does somebody have an hint about that ?

You have to use a theme for your SplashActivity instead of directly setting the image in the layout.For eg:
<style name="Theme.Splash" parent="AppTheme">
<item name="android:windowBackground">#drawable/ic_splash</item>
</style>
Then apply this theme to your splash activity in Manifest.for eg:
<activity
android:name=".controller.activities.SplashActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/Theme.Splash"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Related

Android: Creating a splashscreen on app start WITHOUT timer?

Currently I have a very low-res splashscreen I made by setting the applications theme to a drawable image. This would work PERFECTLY if it wasn't for this. Now I'm looking for an alternative.
The one thing I will not do is create a timed splashscreen, which there are plenty of guidelines on how to make one, the one thing I want to know is how do I create a splashscreen that will load first thing, then finish once MainActivity has finished loading?
The one thing I love about my current splashscreen is that it loads instantly when the app starts, but it will cause major delays when clicking buttons if it's high-res (more than 300x300pixels).
Here's my current code for the flawed, laggy splashscreen that loads and stops based on MainActivity's loaded state:
in styles.xml:
<style name="splashscreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowBackground">#drawable/splashscreen</item>
</style>
in manifest:
in AndroidManifest.xml:
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:fullBackupContent="false"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:label="#string/app_name"
android:theme="#style/splashscreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Check for possible issues with overdraw. It seems that the background (the splash image) is still there. see http://www.curious-creature.org/2012/12/01/android-performance-case-study/ if it applies to your case.
Removing the window background: the background defined in your theme is used by the system to create preview windows when launching your application. Never set it to null unless your application is transparent. Instead, set it to the color/image you want or get rid of from onCreate() by calling getWindow().setBackgroundDrawable(null).

super.onCreate crashes after defining custom splash screen style to Activity?

I wanted to add a SplashScreen to my app and did a little research on the matter. Some tutorials said that you could create an activity and with some timers show it for a few seconds. I couldn't get them working, and then in this page How do I make a splash screen? the second top voted answer said that instead of showing an activity (and because of that wouldn't substitute the white/black launch loading screen but instead add more delays) you should instead create a custom style and assign it to your activity in the Manifest file. I did that, created a new Style like this:
<style name="splashScreenTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/launchscreen</item>
</style>
in the styles.xml and changed my Manifest to this:
<application
android:name=".EFBApp"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivityDrawer"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/splashScreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
When I run my app I can see the launch screen perfectly but then it crashes. By breakpoints I discovered that when the MainActivityDrawer (my main class) gets to the super.onCreate(savedInstanceState); line it then crashes (it goes to the ZygoteInit.java class and after that it crashes while breakpoint debugging). If I take away the android:theme lines in the Manifest it works fine but shows the horrible plain white screen while launching. Any suggestions or ideas? Thanks a lot.
Ok, so I managed to make it not crash, instead of assigning the parent as Theme.AppCompat.NoActionBar, I used just AppTheme and it works now. I hope this helps anyone.

How to hide the title bar in a particular activity style by overriding the Application Style

I want to override a application theme on a particular activity, but its not working for me
This is code on my Manifest.xml:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock.Light" >
<activity
android:theme="#style/MyTheme"
android:name="com.ssdevnet.Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.ssdevnet.Home"
android:label="#string/app_name" />
</application>
And this is what i used in style:
<style name="MyTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="android:windowNoTitle">true</item>
</style>
and its still not working on Android 2.3.6 or below but working on 3 and above.
Also i tried to use this on the oncreate method on class file for that particular page:
requestWindowFeature(Window.FEATURE_NO_TITLE);// Removes title bar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // Removes notification bar
but its not working on my phone running Android 2.3.6 but its working on Emulator running Jellybean and i need something that works on all the versions.
And I need to know some things as i am a newbie to android:
Can we define a Global theme, and override that theme on some activities? if yes, what method can we use?
Or we have to define theme for every activity if we are targeting activities instead of app?
I also want to learn about deploying the custom themes in the app.. if there are some good tutorials and references please share.
Thanks in Advance!
Try using setTheme(..) before calling setContentView(...) and super.oncreate() and it should work fine in the Activity.
Check out the Android developer's site for more information.

Programmatically disabling screen rotations in the entire Android application

How do I programmatically disable screen rotations for an entire Android application?
As in keep it in portrait or Landscape no matter which way device is tilted?
You need to add this to your manifest inside the activity that you want to limit
android:screenOrientation="portrait" //Or landscape for horizontal.
If you want it different between activities just make your manifest look like this.
<activity android:name=".Activity1"
android:screenOrientation="landscape">
</activity>
<activity android:name=".Activity2"
android:screenOrientation="portrait">
</activity>
<activity android:name=".Activity3"
android:screenOrientation="landscape">
</activity>
Fix the orientation in android manifest for every activity
<activity android:name=".SomeNewDesignActivity"
android:screenOrientation="portrait" ></activity>
Too late to the party!
Anyway if you want to disable rotation without forcing the user to choose landscape or portrait you can use in each activity in the manifest
android:screenOrientation="locked"
So your manifest should look like this
<activity android:name=".Activity1"
android:screenOrientation="locked">
</activity>
<activity android:name=".Activity2"
android:screenOrientation="locked">
</activity>
<activity android:name=".Activity3"
android:screenOrientation="locked">
</activity>
So the app will keep the current orientation the user decided to use.
The same behaviour can be obtained programamtically:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
Best way to do screen orientation to potrait/landscap for entire app -
Add following lines in your app theme -
for making all activity portrait -
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:screenOrientation">portrait</item>
</style>
for making all activity landscape -
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:screenOrientation">landscape</item>
</style>

How to set different label for launcher rather than activity title?

This question has been asked before - but with no satisfying answer at all! So I'm trying it again.
I want to give my application launcher icon (the one that is displayed on the startscreen!) a different, shorter caption. It seems the launcher takes its label from the mainfest section about the main activity's label, as here:
<activity android:name="MainActivity" android:label="#string/app_short_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
I already changed the original reference to my app's name #string/app_name to a different, shorter string resource here.
BUT - big BUT: this also of course changes this activity's default title! And I did not want that to happen, there's enough space for a long application name! Setting the long title again in onCreate using the setTitle(int) method does no good either, because the short name will be visible to the user for a short time, but long enough to notice!
And - please don't answer my question by refering to a custom titlebar... I do not want to go that long way, just because of a stupid string title! It's a pain to draw a custom title bar for so little effect!
Is there no easy way to just give the launcher a different string to display?
Thanks for your answers!
Edit: One more reason why having a custom titlebar is a pain is that it will not look like the default titlebar, I would have to explicitly do things to make it look alike on each device! And that can't be a solution if, after all, I don't want a different appearance!
Apparently <intent-filter> can have a label attribute. If it's absent the label is inherited from the parent component (either Activity or Application). So using this, you can set a label for the launcher icon, while still having the Activity with its own title.
Note that, while this works on emulators, it might not work on real devices, because it depends on the launcher implementation that is used.
http://developer.android.com/guide/topics/manifest/intent-filter-element.html
<activity
android:name=".ui.HomeActivity"
android:label="#string/title_home_activity"
android:icon="#drawable/icon">
<intent-filter android:label="#string/app_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Side Note: <intent-filter> can also have an icon attribute, but
inexplicably it does not override the icon specified in the
Activity. This may be important to you if you plan to use the native
ActionBar in SDK 11+, which uses Icon and Logo specified on the
Activity.
Added Info: The label is being inherited from Activity and not the Application.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".StartActivity"
android:label="#string/app_long_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
In this case, app_long_name will be displayed with launcher icon, if we do not put label inside as mentioned above.
I was looking for the same thing and here's what worked for me.
<activity android:name="MainActivity" android:label="#string/app_short_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
This will give a short name to your application launcher icon.
To add a larger name to the application bar you just have to add:
this.setTitle(getResources().getString(R.string.app_name));
to your main activity java file.
Solution of Mark Renouf fails to me (using Nexus 4 and Android 4.4). It fails when using shortcuts, shortcuts use the main activity label instead of the app name. I saw some apps like GMail and Google Keep that works fine. But when you open them, I notice its like a moment between the title is blank and the title appears (which seems better than the app name flashing before setting the title using setTitle()).
So here is the best solution I found:
Create a style where the ActionBar does not show the title/label:
<style name="NoActionBarTitle" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/NoActionBarTitle.ActionBar</item>
</style>
<style name="NoActionBarTitle.ActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:displayOptions">showHome|useLogo</item>
</style>
I'm using a navigation drawer and using a logo (because I use a logo and an icon for my app). You can use whatever but don't use showTitle. Then in the AndroidManifest.xml, set the theme for the MainActivity:
<activity
android:name="com.xx.xxx.MainActivity"
android:logo="#drawable/ic_icon_padding"
android:theme="#style/NoActionBarTitle">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Then, in the onCreate() method of the MainActivity, set the title of your Action Bar:
getActionBar().setTitle(R.string.your_title);
After it, you can call:
getActionBar().setDisplayShowTitleEnabled(true);
Tricky but worth.
This probably won't satisfy what you want to do, but have you thought about creating a splash screen that displays very briefly (with the default title) and then launches your new actual "main" activity with the title of your choosing using the setTitle(int) method? I have not tried this to see if it works but that might create a pleasant work around that does not show of the less than seamless nature of what you are trying to achieve.
For anyone using Support / Appcompat Toolbar via the setSupportActionBar() method, the Activity title can be set in Toolbar XML:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
app:title="#string/activity_title"
...
/>
This will override application and activity labels set in the manifest.
android.support.v7.widget.Toolbar
I found a workaround for this problem
In manifest.xml
Write your app's name in the android:label of the launcher(main) activity.
This will make the label of your main activity same as that of the app label.
Then, in the onCreate() function of your Launcher(main) activity write this statement
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle("main activity label");
}
Here write the label that you want to give to your Launcher(main) activity.
You can do something like this:
public class FooBar extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// change title
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_title);
}
}
You'll have to create a custom layout to hold the title. It could be as simple as (called my_title.xml in this case):
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="foo bar"/>
In your AndroidManifest.xml file you just have to set the title for the app, which is what is going to be shown in the launcher icon. For your activity you don't need to set a title there.
The launcher actually shows android:label and android:icon for activity(ies) that declare
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
so application label is of no use.

Categories

Resources