How to remove default action bar in Android project? - android

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">

Related

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 to remove the title bar from Android app

How to remove the title bar from my app.?
I tried by making changes in manifest file by adding "NoTitleBar" at the end of theme and i also followed the answer given in this question
"How to hide the title bar for an Activity in XML with existing custom theme"
But none of them worked for me.Please help
Use this:
requestWindowFeature(Window.FEATURE_NO_TITLE);
in your Activity.
You could add in your activity before you set view in oncreate function.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
It is because your activity is extending ActionBarActivity. You could replace by extending Activity for your activity.
public class MainActivity extends Activity
I hope this will solve your problem.
In the AndroidManifest.xml file you can find a tag <application
That tag contains android:theme attribute, it must be something like "#style/AppTheme". Open the file styles.xml.
Find a tag style name="AppTheme" and change its parent attribute to be Theme.AppCompat.Light.NoActionBar.
In my case it is
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
To hide the title bar on the preview mode click on the button next to the orientation switcher button, that must open a popup where you can choose a style. Choose one with NoActionBar, for example DeviceDefault.Light.NoActionBar

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"

Android: Issue with hiding title bar

I want to hide the title bar in all activities of my app. To do that, I put the following attribute in the tag:
android:theme="#android:style/Theme.NoTitleBar"
The title bar is now hidden, but my problem is that my app looks weird with that attribute.
Before:
http://imageshack.us/a/img831/6905/screenshot1355296053406.png
with the noTitleBar attribute:
http://imageshack.us/a/img211/581/screenshot1355295921669.png
It looks like there is less contrast..
It makes no difference if the noTitleBar attribute is in the application tag or in each activity tag.
Hope you can help me with my problem.
In onCreate() of activity write following:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
It's probably because you have also removed the Theme of your application together with the title bar.
I'm not sure what your theme was before, but you should extend an existing theme. Something like this in your styles file:
<style name="MyTheme" parent="android:Theme.Light.NoTitleBar.">
</style>
Maybe your parent theme should be android:Theme.Black.NoTitleBar?
You've accepted no answer so I'm going to toss my 2 cents in here:
Adding this snippet of code might be helpful:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

Custom titlebar - system titlebar being shown for a brief moment?

I've got a custom layout I want to use as the titlebar of my android app. The technique found (linked at the bottom) works, but the system titlebar is displayed before onCreate() is called. Obviously that looks pretty jarring, as for a moment the system titlebar is shown, then my custom titlebar is shown:
// styles.xml
<resources>
<style name="MyTheme">
<item name="android:windowTitleSize">40dip</item>
</style>
</resources>
// One of my activities, MyTheme is applied to it in the manifest.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.my_activity);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_custom_header);
}
I could always hide the system titlebar and display my own in-line perhaps with each and every layout, but, that's not very friendly.
Thanks
http://www.londatiga.net/it/how-to-create-custom-window-title-in-android/
I think it's a framework limitation. I had the same problem in some of my applications and the ultimate solution was for me to tell the framework I didn't want a title bar at all and then create my own in my layouts. The include directive made it bearable for me, e.g.:
<include layout="#layout/title" />
When I used requestWindowFeature(Window.FEATURE_NO_TITLE) in my activities, I would have the same issue, I'd see the system title bar briefly while the activity was being build when it first loaded.
When I switched to using a theme to tell the framework I didn't want a title, the problem went away and I now see my own title directly on first load. The styling is easy for that:
<style name="FliqTheme" parent="#android:Theme.Black">
<item name="android:windowNoTitle">true</item>
</style>
I know this doesn't apply to your issue with the custom title, but like ptc mentioned, if you move your custom title into style/theme definitions (which you do by overriding the system title styles in your theme), I think you'll be on the right track.
The same problem happened to me today when I was trying to custom the title. I solved it by set the android:theme to android:style/Theme.NoTitleBar in the AndroidManifest.xml, and call setTheme() to the actual theme I want in my activity's onCreate callback function.
Try creating a custom theme style in XML and then set your activity's theme attribute in the AndroidManifest.xml file.
http://developer.android.com/guide/topics/ui/themes.html#ApplyATheme
The method through setting android:theme does not work for me, I have made it by adding the following code in onCreate() of my Activity subclass:
getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN);

Categories

Resources