Android- hide actionbar during startup and then show it again? - android

My android app has tab navigation using an action bar. It works well, but it bothers me that during the first boot of the app, a small default action bar briefly shows up before being replaced by the real, tab-navigation action bar. My onCreate starts like this:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.activity_main);
//Set up the actionbar
final ActionBar actionBar = getActionBar();
.
.
.
What do I have to do so that the real actionbar will be initialized without a small default one briefly showing before it does on startup?
Thanks

Hide during startup
getSupportActionBar().hide();
After you can show it again with ...
getSupportActionBar().show();
It should be the same with native ActionBar of Android.
you should use this line in manifest and don't use getActionBar()
<item name="android:windowActionBar">false</item>
and once it's finished in the main Activity use below or nothing
<item name="android:windowActionBar">true</item>

put this for your activity manifest definition:
<activity
android:name=".MyActivity"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
>
then inside your oncreate do this to show the actual theme you want used:
setTheme(R.style.AppTheme);

if you're using action bar sherlock and you want to toggle this from a FragmentActivity, then you call
getSherlockActivity().getSupportActionBar().hide();

Related

Is it possible remove home button from actionbar

On my main activity, where there is no way to go back, I'd like to remove the app "home" button in the actionbar.
I think it is confusing for the user, who still can quit the app with the OS back button.
Browsing stackoverflow, I saw a whole lot of people asking this, and not a single answer worked for me. Here is the list :
Removing left arrow from the actionbar in android?
To remove the back arrow button from Action Bar
Remove default home/up button in action mode
how to hide up button in actionbar
How to remove v7 toolbar back button
Setting HomeAsUpEnabled(true) but hide back button actionbar
The answers were usually redondant and could be summarized to following :
ActionBar supportActionBar = getSupportActionBar(); //I target some low API
if(supportActionBar != null) {
supportActionBar.setDisplayShowHomeEnabled(false);
supportActionBar.setDisplayHomeAsUpEnabled(false);
supportActionBar.setHomeButtonEnabled(false);
supportActionBar.setHomeAsUpIndicator(null);
}
I tried every combination of those and nothing worked, whether I try with the default ActionBar or with an XML-declared compat-v7 ToolBar with setSupportActionBar().
I also couldn't see any question adapted for the now recommanded App Bar, and an answer with it would be even greater.
Here is my activity manifest :
<activity
android:name=".activity.WelcomeActivity"
android:logo="#drawable/ic_launcher"
android:label="#string/long_app_name"
android:launchMode="singleTop"/>
So, is it even possible to remove this annoying useless arrow nowadays ?
Create a new style in styles.xml:
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Set this style to your activity in Manifest file. To add the Toolbar, add this to your layout file:
<android.support.v7.widget.Toolbar
android:background="#color/colorPrimary"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.Toolbar>
and then in your Java class:
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
This will remove the top left arrow.
simply put getSupportActionBar().setDisplayHomeAsUpEnabled(false)in onCreate of the activity.

Android API 15. I have toolbars in my activites but they are not shown in XML

Very Novice Android Programmer here. I have this small program where i have my main activity and whenever the user clicks an option, a new activity will open. I am trying to change the color of the top toolbar/actionbar for each different activity. I have tried changing the color through Java code within the activity class in the onCreate() method,
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getActionBar().setBackgroundDrawable(
getResources().getDrawable(R.drawable.gradient));
but the program would always crash whenever I would switch to my activity.
I have looked in the XML file of my activity and the toolbar/action code does not show up anywhere, but it does in my main activity, app_bar_main.xml. I'm wondering why the actionbar shows up in activies if it does not show up in the XML file for the activity. How to change the color of the actionbar for newely added non main activities?
I'm guessing you're using app theme with action bar. In res/styles.xml change your theme to NoActionBar version:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
Now ActionBar shouldn't be visible. Add your Toolbar XML code to other activity layouts.
Try this, it will work:
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable("COLOR"));

How can i remove icon and title from ActionBar in Android on startup?

In my android project, I wish to disable icon and the title in ActionBar.
Here is the code:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getActionBar().setDisplayShowTitleEnabled(false);
getActionBar().setDisplayShowHomeEnabled(false);
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
But always on startup they appear and after a while they disappear but i don't want them at all. How can i remove them on startup?
call setDisplayShowHomeEnabled(false) and setDisplayShowTitleEnabled(false) on your ActionBar.
actionBar.setDisplayUseLogoEnabled(false); should do it.
Or
For Splashscreen you should use this line in manifest and don't use getActionBar()
<item name="android:windowActionBar">false</item>
and once when Splash Activity is finished in the main Activity use below or nothing
<item name="android:windowActionBar">true</item>
Reffer this ----> click here
You can use below code for that -
<activity android:name="YourActivityname" android:theme="#android:style/Theme.NoTitleBar" />
If you want the full screen of your device you can use below code -
<activity android:name="YourActivityname" android:theme="#android:style/Theme.NoTitleBar.Fullscreen" />
And, also refer Developer's Site
Another method
Do this in your onCreate() method.
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//set content view AFTER ABOVE sequence (to avoid crash)
this.setContentView(R.layout.your_layout_name_here);
this refers to the Activity.
Maybe this answer can help you. It helped me.
<quote>
Best method is to set the display options to useLogo in your theme. E.g.
<style name="AppTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/AppTheme.ActionBar</item>
</style>
<style name="AppTheme.ActionBar" parent="android:Widget.Holo.Light.ActionBar.Solid">
<item name="android:displayOptions">useLogo</item>
</style>
This won't actually show the logo (if set) because showHome is not included.
</quote>
try this:
#SuppressLint("NewApi")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
setContentView(R.layout.activity_main);
}
NOTE: The getActionBar() method was added in Honeycomb (API: 11) and later

How to remove the title when launching android app?

I already remove the title in onCreate() method.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
}
The title is not displayed. But still appears when launching the app.
And I can use
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
or put
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
into manifest file because I'm using actionBar. If I did that, the app crashes.
So, my question is, is there any way to remove the title when the app is launching because I am gonna put a splashscreen here. Thanks.
-----------
PLEASE NOTICE:
Thanks for your answers, but I clearly said that I already used actionBar.setDisplayShowTitleEnabled(false);
to hide the title bar of the activity. (as shown in the first picture)
BUT the title bar still appears in the launching screen (as shown in the second picture.)
and
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
and
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
would lead to crash launch. This happens after I used actionbar.
I had the same problem.
Personally, I solved it by replacing my Activity inheritance from
ActionBarActivity to Activity.
Hope this will help someone...
Do this in your onCreate() method.
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
this refers to the Activity.
===========
EDIT:
if you are using ActionBarSherLock
final ActionBar bar = getSupportActionBar();
bar.setDisplayShowTitleEnabled(false);
It might be crashing because you are using this.requestWindowFeature(Window.FEATURE_NO_TITLE); after setContentView();
Use this.requestWindowFeature(Window.FEATURE_NO_TITLE); in onCreate() of your Activity , before setContentView(); statement.
May be i am repeating the same which all are saying but i just need to confirm it.In manifest file have add the theme like the below which i added as sample or anyother way.
<application ....
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:largeHeap="true"> ..
</application>
Just remove all other code related to hide title bar only andonly add this one in the manifest file it works for me.I hope it will work to you too.
Nick Butcher and Katherine Kuan wrote a nice Google Plus post about a smoother app launch experience:
https://plus.google.com/+AndroidDevelopers/posts/VVpjo7KDx4H
However, if you want to be compatible with Android versions below API 14 (for example using AppCompat), the only way I could achieve this is by using a separate launch activity using a theme with no actionbar.
Set your splashscreen as your main activity and set the theme to
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
create and intent to move your splash screen to your actual main activity
Use this:
ActionBar bar = getActionBar();
bar.hide();
or
ActionBar bar = getActionBar();
bar.setDisplayShowHomeEnabled(false);
bar.setDisplayShowTitleEnabled(false);
in res/values/styles.xml
find ...
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
replacing for.
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="windowActionBar">false</item>
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
Save and compile...
Put below three line in onCreate Method before setContentview in your activity which want to display full screen
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Hope below lines will help you
getWindow().clearFlags(
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
You can simply add full screen theme to that activity in your manifest file:
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen"
In your AndroidManifest.xml in application tag set your theme to full screen like in below code.
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"

How to remove default action bar in Android project?

I have created an Android application in Eclipse and when I have setting up I have unchecked every navigation bar. I still have the default navigation bar, how I can remove it?
You can do this in your activity:
ActionBar actionBar = getSupportActionBar(); \\ or getActionBar()
You can then hide it like this:
actionBar.hide();
Please note the warning about this in the "Removing the action bar" section of http://developer.android.com/guide/topics/ui/actionbar.html
In an app I made, I removed the title/ActionBar using this code in the onCreate method:
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main); //insert your own layout here
Make sure that the requestWindowFeature method appears before the setContentView method, because otherwise your Activity will crash.
First of all create a new theme/style within your styles.xml in the resources folder. Insert the following code within your resource tags:
<style name="noActionBar" parent="Theme.Base"></style>
By using parent "Theme.Base" it creates a blank screen to work on. Then just set your android theme to your new style in the android manifest, within the 'application' tags.
android:theme="#style/noActionBar"
Please note that if your class file for your activity contains any reference to the ActionBar it may crash when compiling.
Go in styles.xml and change to:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

Categories

Resources