I'm writing an app which will be on embedded device, and I need to remove ActionBar alongside the TitleBar and ContentOverlay.
I found a solution and inserted the following in my styles:
<style name="NoActionBar" parent="#android:style/Theme.Holo.Light">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
and also add the line to my activity in AndroidManifest:
android:theme="#style/NoActionBar"
and in the end I got no title bar, no content overlay, however the ActionBar is still there. Please advice. I use android:theme="#android:style/Theme.Holo.Light" and my targetSdkVersion is 18.
Small mistakes in XML can cause very strange problems,
which are not always reported accurately by the build process.
I tend to shy away from changing XML, when I can do it in java.
Java gives you more control.
programmatically remove action bar
----------------------------------
from normal activity
getActionbar().hide();
getActionbar().show();
if your using support activity
getSupportActionBar().hide();
getSupportActionBar().show();
and from the Fragment you can do it
getActivity().getActionbar().hide();
getActivity().getActionbar().show();
remove title bar
----------------
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);
}
}
ActionBar ContentOverlay
------------------------
1) Request for actionbar overlay programmatically by calling
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
// this 'requestFeature()' must be requested from your activity 'onCreate()' method
// before calling for 'setContentView(R.layout.my_layout)':
2) set the actionbar color by calling setBackgroundDrawable() like so:
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00212121")) );
Try changing your style's parent like this :
parent="#android:style/Theme.Holo.Light.NoActionBar"
Example
<style name="NoActionBar" parent="#android:style/Theme.Holo.Light.NoActionBar">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
I had to extend my Activity with theme Theme.AppCompat.Light.Dialog from ActionBarActivity before and now from AppcompatActivity, because my Base Activity extends this one.
But now with new appcompat v7 (v22) library my Activity started to show title bar despite the fact that i use custom style with items windowActionBar=false, android:windowNoTitle=true. But until appcompat library upgraded there isn't such problem, title bar wasn't showed.
If my activity extends FragmentActivity everything is ok and i understand that maybe i use a bad pattern that my dialog activity extends from AppcompatActivity but i would like to know is there a way to remove title bar?
I had same issue and needed to do something like following to resolve (note use of "windowNoTitle" instead of "android:windowNoTitle")
<style name="Theme.MyDialog" parent="#style/Theme.AppCompat.Light.Dialog">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Try
getSupportActionBar().hide()
if you are using AppCompatActivity
And
getActionBar().hide()
if your activity extends ActionBarActivity.
Hope it helps.
You can hide the action bar at runtime by calling hide(). For example:
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
Only one thing work in AppCompat Theme -
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
To solve the actionbar on class extend AppCompatActivity I start with define new theme extend from main theme in style.xml file :
style.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
and implement noactionbar theme to activity that you want in AndroidManifest.xml. Hope this help :)
If you're using support library use:
getSupportActionBar().setDisplayShowTitleEnabled(false);
If not then use
getActionBar().setDisplayShowTitleEnabled(false);
Adding android:theme="#style/AppTheme.NoActionBar" in AndroidManifest.xml does the trick in my case.
#Brexx Galangue solution gave me the following runtime error:
java.lang.RuntimeException: Unable to start activity
Caused by: java.lang.IllegalStateException: You need to use
a Theme.AppCompat theme (or descendant) with this activity.
Try to add this code on your manifest, specifically, to the activity that you want to disappear its Actionbar:
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" >
hope it helps :D
public class MainActivity extends AppCompatActivity {
#Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.custom_title_bar);
}
}
I wished to make one of my activities to look like a dialog and used a Theme.AppCompat.Dialog theme for it, but it made it's action bar to look bad (see below).
Now background is cut to the length of the title string and I cant't find any theme property to fix it.(
What can be done to avoid it?
Related part of styles.xml:
<style name="DeviceListTheme" parent="Theme.AppCompat.Dialog">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
I start the activity using the following code:
Intent intent = new Intent(this, DeviceListActivity.class);
startActivityForResult(intent, REQUEST_CONNECT_DEVICE);
First, when I encountered this problem, I tried using supportRequestWindowFeature(Window.FEATURE_NO_TITLE); but this didn't work for me and had no effect.
The alternative method to remove the bar at the top of your dialog activity would be to create a custom style and apply it to that activity.
In styles.xml, create a new style like so:
<style name="MyCustomDialog" parent="Base.Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
Now, in AndroidManifest.xml, add in android:theme="#style/MyCustomDialog" to your activity.
Of course, MyCustomDialog can be renamed to anything you want.
Use DialogWhenLarge instead of standard Dialog style:
<style name="MyDialogTheme" parent="#style/Theme.AppCompat.Light.DialogWhenLarge">
...
</style>
I solved the same problem this way:
Activity:
public class MyActivity extends android.support.v4.app.FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_layout);
setTitle("View task");
}
}
Theme:
<style name="Theme.MyDialog" parent="#style/Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">false</item>
</style>
Manifest:
<activity android:name=".MyActivity" android:theme="#style/Theme.MyDialog"/>
Result:
Its Working
<style name="AppThemeDialog" parent="Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:spinnerStyle">#style/holoSpinner</item>
</style>
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
setTitle("Batches");
}
In my app there is this title bar at the top where the overflow menu would be, but I don't need settings and only have one screen.
When I change the theme like described in many other questions I get the old 2.2 theme. I want to have the modern theme just without the bar at the top.
Go to styles.xml and change .DarkActionBar for .NoActionBar
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
becomes
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
if colors are irrelevant to your app, you can actually go for
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar" />
In the manifest file Change:
android:theme="#style/AppTheme" >
android:theme="#style/Theme.AppCompat.NoActionBar"
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
works in onCreate() when put before setContentView() is invoked.
otherwise it crashes
Check this
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
In styles.xml file, change DarkActionBar to NoActionBar
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
Go to Project -> app -> main -> res -> values -> styles.xml
Change this line if you want to delete it for every view
`<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">`
to
`<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">`
if you want to make it just for one view you can change it in youre manifest data. Go to Android -> manifests -> AndroidManifest.xml. do following:
Search the View you want to get this type of change <activity android:name"...">
Add android:theme=""#style/Theme.AppCompat.NoActionBar"
This works for me
getSupportActionBar().hide();
This was working for me on values/styles.xml add items:
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
In the manifest file change to this:
android:theme="#style/Theme.AppCompat.Light.NoActionBar" >
open styles.xml
insert
<style name="no_title" parent="AppTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
you can change name="---------"
open Androidmaifest.xm
find android:theme="#style/AppTheme" chang to android:theme="#style/no_title"
click select Theme on menubar (it's green color near MainActivity)
click project Theme
click no_title (on you right hand Side)
click OK
For Beginner Like Me. Just Do it what I say.From your Android Project.
app -> res -> values -> style.xml
replace this code
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>
Enjoy.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_main);
Just simply put getSupportActionBar().hide();
between super.onCreate and setContentView method.
do this in you manifest file:
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
delete the following from activity_main.xml
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay"/>
contact me for more help
Newer versions replaced styles.xml with themes.xml
Go to Project -> app -> res -> values -> themes -> themes.xml
and change e.g.
<style name="Theme.MyApplication" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- omitted for brevity -->
</style>
to
<style name="Theme.MyApplication" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- omitted for brevity. -->
</style>
Switching the parent to NoActionBar
Do this for both themes.xml files
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
in onCreate() works!
Try changing styles to NoActionBar if that doesn't works add this code to your main activity
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
setContentView(R.layout.activity_main);
}
This works for me i hope this work for you as well
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
}
Best way is to use actionbar function setTitle() if you wish to show logo or have some other stuff in you actionBar but dont want to see name of the app, write this code in MainActivity.java or anywhere you wish to hide title in onCreate:
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setIcon(R.mipmap.full_white_logo_m); // display logo
actionBar.setTitle(""); // hide title
This way your app won't have reason to crash.
Just use setTitle(null) above
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
The title will disappear then you can use the logo of your choice.....
I have faced the same problem as you, and solve this problem just by changing the class which I extended.
//you will get the app that does not have a title bar at the top.
import android.app.Activity;
public class MainActivity extends Activity
{}
//you will get the app that has title bar at top
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity
{}
I hope this will solve your problem.
In Kotlin, this is how to do.
val actionBar: ActionBar? = supportActionBar
actionBar?.hide()
The easiest way is to just double click on this button and choose "NoTitleBar" .
In AndroidManifest.xml of your application you'll find the android:theme for example set to #style/AppTheme
Now go to styles.xml, find the style tag, make sure that name is set to AppTheme the same as in manifest and set parent to android:Theme.Holo.Light.NoActionBar
(also do this in styles(v21) if you have it in your project)
<style name="AppTheme" parent="android:Theme.Holo.Light.NoActionBar">
<!-- ... -->
</style>
Just call setTitle(null); in onCreate()
try:
toolbar.setTitle(" ");
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setTitle("");
setSupportActionBar(toolbar);
}
To simply remove the title bar (which means the bar contains your app name) from an activity, I simply add below line to that activity in the manifests\AndroidManifest.xml:
android:theme="#style/AppTheme.NoActionBar"
It should now look like below
<activity
android:name=".MyActivity"
android:theme="#style/AppTheme.NoActionBar"></activity>
Hope it'll be useful.
At Project tab, find
app>res >values > themes >theme.xml
Change the value of parent in the above shown image.
New versions of Android Studio have themes.xml instead of styles.xml. So go to res/values/themems/themes.xml and change .DarkActionBar to .NoActionBar
This also solved my problem, but before it did I couldn't find the styles.xml resource.
Eventually I found a solution and it turns out that the theme attribute is now inside the themes.xml not the styles.xml Here is my example
i want to set my Activity full Screen with Title bar , how can i do this ? thanks
In styles.xml:
<resources>
<style name="Theme.FullScreen" parent="#android:style/Theme.Holo">
<item name="android:windowNoTitle">false</item>
<item name="android:windowFullscreen">true</item>
</style>
</resources>
Refer to your custom style in your mainfest:
<activity android:name=".MyActivity" android:theme="#style/Theme.FullScreen"/>
To be truthful I've not tested this combination myself.
This worked for me:
// Remove System bar (and retain title bar)
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
In code it would look like this:
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class ActivityName extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Remove System bar (and retain title bar)
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Set your layout
setContentView(R.layout.main);
}
}
To create a full screen app with a custom title style, override some attributes of a full screen theme like so:
<style name="AppTheme" parent="#android:style/Theme.Light.NoTitleBar.Fullscreen">
<item name="android:windowNoTitle">false</item>
<item name="android:windowTitleSize">45dip</item>
<item name="android:windowTitleBackgroundStyle">#style/TitleBackgroundStyle</item>
</style>
<style name="TitleBackgroundStyle">
<item name="android:background">#drawable/title</item>
</style>
and modify as you wish.
I suggest you to set fullscreen theme for activity e.g. Theme.Black.NoTitleBar.Fullscreen and create custom title bar in activity layout.
Set your App theme as Theme.Holo.Compactmenu to make your title bar visible along with the icon