I Have set an image in my ActivityMain.xml, and there is no action bar theme is used. I want
The photo that I set in the background this image will show the background of the status bar.
You need can achieve that by following steps:
Declare one theme in your styles.xml
<style name="FullScreenTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="colorPrimary">#color/background</item>
<item name="colorPrimaryDark">#color/background</item>
<item name="colorAccent">#color/primary</item>
<item name="colorControlActivated">#color/primary</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">false</item>
<item name="android:windowTranslucentNavigation" tools:targetApi="kitkat">true</item>
<item name="android:statusBarColor" tools:targetApi="lollipop">#android:color/transparent</item>
</style>
Note: android:windowTranslucentNavigation is important attribute here.
Now in your activity xml's parent layout, add android:fitsSystemWindows="true" to fill your UI in full screen.
in your Activity class, inside onCreate Method, need to set NO_LIMIT flag like this;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
setContentView(R.layout.your_xml);
}
Now set this theme your class from android manifest.
<activity
android:name=".YourActivity"
android:theme="#style/FullScreenTheme" />
Hope, this will helps you.
What I assume from your question is that you want to achieve a Full Screen Activity with your blue color as background of status bar for that you can set your status bar to transparent and your screen to stretch out to full screen
window?.decorView?.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
window.statusBarColor = Color.TRANSPARENT
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'm trying to hide the title bar in fullscreen mode. When i try to use Activity, the title bar vanishes. But when i use AppCompatActivity, it still remains. Any idea why this happens? Should i change something else such as the manifest? Here is the code which i have used to hide the title bar and go fullscreen:
public class MoreInfoNotification extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.more_info_notification);
}
Thanks. Cheers!
When using an AppCompatActivity to remove the ActionBar/Title the theme of that activity; specified in the styles.xml file must be one of the NoActionBar themes:
Theme.AppCompat.Light.NoActionBar
Theme.AppCompat.NoActionBar
Got it.
I created a new theme for the activity MoreInfoNotification with parent as the previous activity.
<!--Theme for parent activity-->
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<!--Theme for new activity-->
<style name="MoreOnNotificationTheme" parent="AppTheme.NoActionBar">
<item name="android:windowNoTitle">true</item>
</style>
There is NO NEED to add the following lines in the MoreInfoNotification activity:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
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