How to hide the actionbar before the Activity is loaded? - android

My goal is to show a splash screen on my applications startup. Right now what it will do is briefly show the actionbar with an otherwise blank page, then jump to the splash screen. I'm trying to figure out how to not show the beginning screen and just start with the splash screen.
I'm trying to use these links for information on how to solve this.
ActionBar Lag in hiding title
In this one I'm assuming I can use the same type of method for hiding the actionbar by changing the theme, but I don't know what I would actually use as my style to do so.
How to hide action bar before activity is created, and then show it again?
and here it talks about adding a line to the manifest that would do it. Where in the manifest? Anywhere I put it did not do anything.

try this in manifest file
<activity
android:name="yourActivityName"
android:label="your label"
android:theme="#android:style/Theme.Holo.Light.NoActionBar.Fullscreen" >
</activity>

Check this link Android: hide action bar while view load
Code snippets from the link, incase the link breaks down, courtesy #kleopatra:
Setting the properties windowNoTitle to true on your theme will
hide the ActionBar. use two different themes both extending parent="Theme.AppCompat.Light" in order to prevent NPE when using getSupportActionBar
set the styles as
<style name="AppThemeNoBar" parent="Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
</style>
<style name="AppThemeBar" parent="Theme.AppCompat.Light">
<item name="android:windowNoTitle">false</item>
</style>
Due to some odd behaviour on versions < 11, you need to add
if (Build.VERSION.SDK_INT < 11){
getSupportActionBar().hide(); }
inside activities that do not need the actionbar

Delete the "android:label" entries in Manifest file, from application and the first activity which is loaded. In your case, the Splash activity.
Sample...
<application
android:allowBackup="true"
android:icon="#drawable/starticon"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo">
<activity
android:name=".ActivitySplash"
android:label="#string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

Just add this code in your Activity in the onCreate function.
val actionBar = supportActionBar?.apply{hide()}

Related

How to disable the title on the ActionBar in Main Launcher Activity

I checked this issue, couldn't find an answer.
there are 3 places I checked that show the label on 3 separated places in my android phone or app.
Under the logo of the app
In the app processes which show's the active apps, (from that window you can close the app process)
In the most annoying place, the "splash" action bar title (It happens before the MAIN activity UI start, when it loading the activity onCreate I believe), which most of us want to get rid of usually.
The 3 places are:
<application
android:name=".Application"
android:icon="#mipmap/icon"
android:label="#string/app_name" <!-- 1--- the first place-->
android:theme="#style/AppTheme">
<activity
android:name=".LoadingActivity"
android:label="#string/app_name" <!-- 2--- the second place-->
android:theme="#style/AppTheme.NoActionBar">
<intent-filter android:label="#string/app_name"> <!-- 3--- the third place-->
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
I checked on my phone (LG4 - android 5.1).
I saw that place 2 print on the action bar and the process but place 3 print on under the app icon in the phone.
BUT! when I checked in another phone (Hawaii P9 - android 6.0)
I saw place 2 printed under the app icon in the phone, unlike in LG4 which was place 3 who did this.
The main reason I actually checked it, is that I don't want the title to appear in the action bar, while I want it to appear under the app icon and in the processes.
Any help from an expert?
sorry for commenting in the answer section but that's cuz of the low reputation, will you add your onCreate method code in order to tell you how to use
.setTitle(" ");
in which you set the title blank to make the app name doesn't appear if that helps you
1) You could override the action bar , to use your custom action bar layout.
getSupportActionBar.setCustomView("your custom view");
2) If you just want to hide the title , you could set the title using
getSupportActionBar.setTitle("");
getSupportActionBar.setSubtitle("");
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle("");
}
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayShowTitleEnabled(false);
}
From the answers you gave me, I figure a way to do what I need in a way.
I changed the main launcher activity to extend from AppCompatActivity instead of Activity, that way I could use your suggerstions you listed.
(Although I still wonder how to do it with the regular Activity)
The style themes was also enough for me, and it worked in a neater way!
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/colorPrimaryDark</item>
<item name="background">#color/colorPrimaryDark</item>
</style>
<style name="MyAppTheme.NoActionBar" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/colorPrimaryDark</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="android:statusBarColor">#color/colorPrimaryDark</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowBackground">#color/colorPrimaryDark</item>
<item name="android:actionBarItemBackground">#color/colorPrimaryDark</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
This xml style, fix the selected PrimaryColor in all of the wanted places and won't show the title in the main launch activity loading actionbar, while showing it under the icon and in the processes!

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.

Android - Disable dummy starting window of application

I want to know how to achieve this effect.
My app (default everything), when launcher icon is clicked, right away display some kind of a empty dummy window, where nothing is happening and then loads layout into it.
"Heavier" apps like YouTube, Drive, Dropbox etc. when started, seem to wait after launch, without showing that dummy window and load right into ready layout.
Any idea how to do this or where should I look into?
Thanks
//EDIT: this has nothing to do with something like loading database, where I should display progressBar, imho this has to do with stuff before activity exists.
I suggest you don't disable the dummy loading window using:
<style name="Theme.MyTheme" parent="android:style/Theme" >
....
<item name="android:windowDisablePreview">true</item>
....
</style>
because you could run into several problems. For example, if you try to animate an AlertDialog, enter animation will not work (personal experience).
The right solution is to set the theme of your application like to your main activity screen (same ActionBar style, same background color).
In my application after severals experiments i found the right solution for my needs.
(I have a main activity with blank background, no ActionBar, just full screen personal layout)
1 - styles.xml: add new style like this (remove ActionBar and set the same background color of my main activity)
<style name="LoadingTheme" parent="#android:style/Theme.Light.NoTitleBar.Fullscreen">
<item name="android:windowBackground">#color/white_smoke</item>
</style>
2 - AndroidManifest.xml: set my theme for main activity to "LoadingTheme"
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.company.appname.MainActivity"
android:label="#string/app_name"
android:theme="#style/LoadingTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
....
</application>
And finally i have full blank dummy loading window without ActionBar with soft MainActivity load and working animations.
Hope to be helpful.
<style name="Theme.MyTheme" parent="android:style/Theme" >
....
<item name="android:windowDisablePreview">true</item>
....
</style>
but use with caution
This will create a custom preview window for your activity.
Create a style in styles.xml like
<style name="MyTheme" parent="#android:style/Theme.Holo.NoActionBar">
<item name="android:windowBackground">#color/myBackgroundColor</item>
</style>
In your Manifest file use the theme created above.
For eg:
<activity android:name=".MyActivity"
android:label="#string/app_name"
android:theme="#style/MyTheme"
/>
In your activity change the background of the window back to null in onCreate()
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setBackgroundDrawable(null);
setContentView(R.layout.main);
}
You can call the setContentView method anywhere you'd like in your activity. Before calling this method it will display a blank screen. If you wanted a splash screen, you can call the setContentView method within the onCreate method to display the splash screen view. Then when you're ready to display the "main" view you can use a LayoutInflater to display it. I also suggest using a ProgressDialog to show the user that information is loading.
Load your resources before setting the contentview. There will be a dummy window until you would not set view using setContentView.
EDIT
To avoid this screen. Make there changes to your code.
1) Do not do any heavy work in activity onCreate method. Run a separate thread for it.
2) Set content view right after the super.onCreate() line
super.onCreate(savedInstanceState);
setContentView (R.layout.splash_screen);
3) Apply following theme to your application.
Define theme in style
<resources>
<style name="Theme.MyTheme" parent="android:style/Theme" >
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#drawable/any_default_background</item>
</style>
</resources>
In your Manifest
<application
....
android:theme="#style/Theme.MyTheme"
....
>
Thats It.

Programmatically turn off android:windowActionBarOverlay style from action bar

Currently, I am using ActionBarSherlock. I want to launch SecondActivity from MainActivity.
MainActivity is using action bar with windowActionBarOverlay style turned on. SecondActivity is using action bar with windowActionBarOverlay style turned off. Hence, here is how my XML looks like.
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:debuggable="false" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/ThemeWithActionBarOverlay"
android:screenOrientation="nosensor" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:theme="#style/ThemeWithoutOverlay">
</activity>
</application>
<resources>
<style name="ThemeWithActionBarOverlay" parent="#style/Theme.Sherlock">
<item name="android:windowActionBarOverlay">true</item>
<item name="abIcon">#drawable/ic_home</item>
<item name="abTitleTextStyle">#style/ActionBarCompatTitle</item>
</style>
<style name="ThemeWithoutOverlay" parent="#style/Theme.Sherlock">
<item name="abIcon">#drawable/ic_home</item>
<item name="abTitleTextStyle">#style/ActionBarCompatTitle</item>
</style>
</resources>
However, by doing so, in SecondActivity, I realize I can never have a up/back button on the top left of action bar. Although there is icon being shown, it is not pressable. Only by using back same theme (ThemeWithActionBarOverlay) as MainActivity, only up/back button will shown. However, if I let SecondActivity to use same theme as MainActivity, I find out no way to turn off windowActionBarOverlay behaviour.
// SecondActivity
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.history_list_activity);
ActionBar actionBar = this.getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
// How to turn android:windowActionBarOverlay attribute to false during runtime?
// actionBar.???
}
My questions are
Why the child activity has to use action bar with same theme as parent's, in order to have proper up/back button shown? Is there any way I can use different themes, yet have up/back button appears on child activity?
Is it possible to turn of windowActionBarOverlay style during runtime?
To answer your first question, you don't need to have the parent and child activity using the same theme for the 'Up' button to work. In fact, I'm working on a similar parent/child activity application, and its working just fine using two different themes( a theme without overlay for the parent, and the fullscreen theme (with overlay) for the child).
There must be another reason why it is not working...
Make sure you have defined MainActivity to be the parent of second activity. You can do that either by code, or the prefered way, in the AndroidManifest.xml:
<activity
android:name=".SecondActivity"
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
Make sure that in your child activity, you have activated the 'up' navigation:
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
For your second question, try overriding the 'windowActionBarOverlay' in the 'ThemeWithoutOverlay' theme to false:
<style name="ThemeWithoutOverlay" parent="#style/Theme.Sherlock">
<item name="android:windowActionBarOverlay">false</item>
<item name="windowActionBarOverlay">false</item><
<item name="abIcon">#drawable/ic_home</item>
<item name="abTitleTextStyle">#style/ActionBarCompatTitle</item>
</style>

How to hide title bar from the beginning

I am using following code to replace title bar.
final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
And it's working fine once UI loaded. Problem is however when I start the app, the ugly gray bar appears for 1-2 seconds until UI loaded. Is there any way to specify not showing the default title bar at all?
If you want the titlebar to be gone in every activity within your app, then add
<application android:name=".YourAppNameHere"
android:label="#string/app_name"
android:icon="#drawable/icon"
android:theme="#android:style/Theme.NoTitleBar">
to your manifest. Not 100% sure though that this will prevent the titlebar from showing up momentarily, but it should work.
In the Manifest file, add this line inside the application tag
android:theme="#android:style/Theme.NoTitleBar"
It will hide the bar from all the activities. If you want to hide it from a specific activity, add the same line to that activity's tag.
Good Luck !
You should add a line to your AndroidManifest which states that you use a theme (standard android or extended)
<application android:name=".YourAppNameHere"
android:label="#string/app_name"
android:icon="#drawable/icon"
android:theme="#style/MyTheme">
and then you can have a themes.xml in your res/values/ folder where you extend the: Theme.NoTitleBar and add custom rules to them (for example like windowBackground)
<resources>
<style name="MyTheme" parent="android:Theme.NoTitleBar">
<item name="android:windowBackground">#drawable/my_background</item>
</style>
<resources>
Have fun

Categories

Resources