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

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!

Related

Activity with no Title/Action bar

First off, I'm not completely sure that Title Bar and Action Bar are the same? 2 different things?
I have an existing application that I need to maintain. In I have an activity that had a custom view as a title. What I want is to have the default title bar for the activity - the native one. I removed the custom view, and in the activity class I removed requestWindowFeature(Window.FEATURE_NO_TITLE); but the activity still doesn't show the Title bar. I've set the activity theme to android:theme="#style/Theme.AppCompat.Light". Still no Title Bar.
The activity intent is started with launchActivityForResult - don't know if that has anything to do with that.
What am I missing here? Is there a way to show it programmatically?
title-bar and action-bar is different thing.
use theme like this.
Theme.AppCompat.Light
instead of
Theme.AppCompat.Light.DarkActionBar
<style name="MyMaterialTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
and add this theme to manifest
<application
android:name="com.qwesys.ecommerce.application.AppController"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="#style/MyMaterialTheme">
First off, I'm not completely sure that Title Bar and Action Bar are the same? 2 different things?
Yes these are 2 different things implementation wise. Action Bar is now deprecated and we use something called the toolbar.
https://developer.android.com/reference/android/widget/Toolbar.html
You can make customized toolbar https://developer.android.com/training/appbar/setting-up.html
And for your second part use startActivityForResult() and like suggested by #sagar above you use the theme to to make the toolbar appear.

How to create Android application without ActionBar using new theme in API9?

I need to create application wihtout actionbar. I will try to explain how I create application(maybe I am missing some steps).
1.I am intentionally not choosing "Holo Light with Dark Action Bar" option. I thought this make application without action bar.
2.Leaving next page as default:
3.Leaving next page as default:
4.On the next page, it becomes interesting. Blank Activity's description says that it creates a new blank activity an action bar. On Empty Activity's description: Creates a new empty activity. So I choose Empty activity
5.Leaving next page as default.
Result:As usually, application was created with ActionBar.
Tried this solution:getActionBar().hide();. In this solution, ActionBar is hiden after some milliseconds.
Tried to use android:theme="#android:style/Theme.NoTitleBar" in AndroidManifest.xml->application tag. But in this solution, application uses old theme.
My question: how to create Android application without ActionBar using new theme and leaving StatusBar enabled?
PS. I remember, about one year ago, in Eclipse, applications were created without ActionBar. Then we added it manually
Put this right after super.onCreate(savedInstanceState); in the onCreate method of your activity(s):
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Make sure you put this BEFORE this.setContentView(R.layout.activity_example); to avoid crashes
When your project is started you can use public activity extends Activity instead of using ActionBarActivity this will also remove the action bar or there is another way
<android:theme="#android:style/Theme.NoTitleBar">
or you can see these links they might help
How to hide action bar before activity is created, and then show it again?
Remove android default action bar
Refer this code and change as per your requirement:
Update :
styles.xml :
<style name="FullscreenTheme" parent="android:Theme.Holo">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:actionBarStyle">#style/FullscreenActionBarStyle</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">#null</item>
<item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
<item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
</style>
<style name="FullscreenActionBarStyle" parent="android:Widget.Holo.ActionBar">
<item name="android:background">#color/black_overlay</item>
</style>
These will remove actionbar and keeps your theme as it is .
Note : Here i have tested using Theme.Holo . you can use yours.
AndroidManifest.xml
<activity
android:name=".GridViewExample"
android:theme="#style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
It gives you activity without ActionBar.
Hope this solves your problem.
You can do it programatically:
public class ActivityName extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// remove title
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
}
Or you can do it via your AndroidManifest.xml file:
<activity android:name=".ActivityName"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"/>
EDIT :
If your app uses any other theme use corresponding theme name E.g. For White theme #android:style/Theme.Holo.Light.NoActionBar.Fullscreen

How to remove the Activity title from Action Bar Sherlock without losing it from the 'RecentApps' chooser?

I am having problems trying to remove the Activity title text from my Action Bar Sherlock.
I have spent(wasted) a lot of time trying to find a solution and just cannot make this work.
I have a Splash Activity on which I go full screen. But just before the Splash Activity appears, a screen appears (for a very short period of time) that has nothing but an Action Bar with the App Icon and Activity Title Text. I do not understand why it appears. Is this default Android behavior? I want to avoid this screen, or at least remove the Activity Title from the Action Bar on this screen. If I set it to "", I lose the app from the Recent Apps chooser.
Please refer to these images:
Pre Splash :
Splash Screen :
I have referred to the following examples on SO and also searched elsewhere. But nothing seems to work.
Remove the title text from the action bar in one single activity
Action Bar remove title and reclaim space
How do you remove the title text from the Android ActionBar?
How can I remove title and icon completetly in Actionbar sherlock?
Please check my Android Manifest and the theme file...
<application
android:name="com.zipcash.zipcashbetaversion.MyApplication"
android:allowBackup="true"
android:icon="#drawable/zipcash_icon"
android:label="#string/app_name"
android:logo="#drawable/zipcash_logo_small"
android:theme="#style/Theme.MyTheme" >
<activity
android:name="com.zipcash.zipcashbetaversion.SplashActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.zipcash.zipcashbetaversion.SignUpActivity"
android:label="#string/title_activity_sign_up"
android:screenOrientation="portrait" >
</activity>
And so on...
The following is my theme file:
<style name="Theme.MyTheme" parent="Theme.Sherlock.Light">
<!-- Set style for Action Bar (affects tab bar too) -->
<item name="actionBarStyle">#style/Widget.MyTheme.ActionBar</item>
</style>
<style name="Widget.MyTheme.ActionBar" parent="Widget.Sherlock.ActionBar">
<!-- define background for action bar (sets default for all parts of action bar - main, stacked, split) -->
<item name="android:background">#drawable/background</item>
<item name="background">#drawable/background</item>
<!-- set background for the tab bar (stacked action bar) - it overrides the background property -->
<item name="backgroundStacked">#color/action_bar_tab_background</item>
<item name="titleTextStyle">#style/NoTitleText</item>
<item name="subtitleTextStyle">#style/NoTitleText</item>
<item name="displayOptions">showHome|useLogo</item>
</style>
<style name="NoTitleText">
<item name="android:textSize">0sp</item>
<item name="android:textColor">#00000000</item>
<item name="android:visibility">invisible</item>
</style>
I have also written this code in my Splash Activity:
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayOptions(actionBar.getDisplayOptions() ^ ActionBar.DISPLAY_SHOW_TITLE);
actionBar.hide();
ActivityHelper.initialize(this);
setContentView(R.layout.activity_splash);
Have I made a mistake that I am overlooking. Is there something else I should do. My minimum API level is 8.
Any help will be appreciated.
You can add this to your activity:
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" >
When you first launch your app and Application onCreate haven't finished loading you see the empty lag screen. You can set the window background to green and remove the ActionBar for Application theme, so it will look splash-like.
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="splash_background">#86bf3a</color>
</resources>
styles.xml
<style android:name="SplashTheme" parent="#style/Theme.Sherlock.Light.NoActionBar">
<item name="android:windowBackground">#color/splash_background</item>
</style>
Make application use splash theme with green background and no ActionBar
<application
...
android:theme="#style/SplashTheme" >
<activity
android:name="com.zipcash.zipcashbetaversion.SplashActivity"
....>
<!-- .... -->
</activity>
<!--...
make all other Activities use MyTheme
...-->
<activity
android:name="com.zipcash.zipcashbetaversion.SignUpActivity"
...
android:theme="#style/Theme.MyTheme" />

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.

How to hide the actionbar before the Activity is loaded?

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()}

Categories

Resources