So I know there are a ton of these questions, but every time I try what they say, my app does not seem to remove the title bar. I have done the style change:
<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>
<item name="android:windowNoTitle">true</item> <!-- This should work but it does not -->
</style>
I have also tried:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide(); //This guy here
setContentView(R.layout.activity_title);
The above works but I still want to use the space the title bar takes for content in my app, which is why I want to be able to modify the XML code rather than use java. Any suggestions?
You can either:
<style name="noActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
and in your layout(at the root layout)
android:theme="#theme/noActionBar"
Or
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
However, the last one also hides the Statusbar. You can also set the theme to a default theme(look through the themes and find those with NoActionBar). The last one is useful if you have no plans to style the activity(for an instance if you use SurfaceView) with custom colors, etc.
For an instance you can change AppBaseTheme to have the parent Holo.Light.NoActionBar or any similar theme, but the name has to contain NoActionBar, othervise it has an actionbar
Add the below theme to style.xml:
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Then set this theme to your Activity in manifest:
<activity
android:name=".MainActivity"
android:theme="#style/AppTheme.NoActionBar" />
I would like to change the color of my settings Tab located on the ActionBar, I have done very extensive research here and in other sources.
My Android version is 4.4.2.
My manifest is declared this way:
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="19" />
Basically I am doing what other sources showed me to:
<style name="AppBaseTheme" parent="android:style/Theme.Holo.Light">
</style>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:panelFullBackground">#drawable/menu_background</item>
</style>
I also have replaced the android:panelFullBackground property for android:panelBackground, android:panelColorBackground and android:panelColorForeground switching from drawable resources to color values for each without results.
Finally I have also tried using ListPopupWindow parent variant:
<style name="AppBaseTheme" parent="android:style/Theme.Holo.Light">
</style>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:popupMenuStyle">#style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="#android:style/Widget.Holo.ListPopupWindow">
<item name="android:panelFullBackground">#drawable/menu_background</item>
</style>
Here I have also switched the android:panelFullBackground property for android:panelColorBackground and android:popupBackground properties mixing them up with #android:color and #drawable resources too but is not working either.
Can you please tell me an effective way to configure this through the styles.xml file?
Thank you very much
Maybe you need to use Android Asset studio's ActionBarStyleGenerator to easily handle colors and not going through all the stuff. If you need more customizing on each Tab then you need to get a reference to actionbar using getActionBar()(or getSupportActionBar() in case of support actionbar) and create custom views Programmatically and add them to your actionbar using addTab(...)
I managed to find the right setting for my styles to accomplish the action bar settings custom color. This post helped as well: How to change the background color of Action Bar's Option Menu in Android 4.2?
The styles go this way:
File styles.xml:
<resources>
<style name="AppBaseTheme" parent="android:style/Theme.Holo.Light">
</style>
<style name="AppTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBarTheme</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item>
<item name="android:itemTextAppearance">#style/TextAppearance</item>
</style>
<style name="MyActionBarTheme" parent="#android:Widget.Holo.Light.ActionBar">
<item name="android:background">#3892D3</item>
<item name="android:titleTextStyle">#style/MyActionBarTheme.Text</item>
</style>
<!--
This style reference did it, you can put a drawable resource or color resource reference there as well. For example: #drawable/menu_dropdown_image or #android:color/white
-->
<style name="PopupMenu" parent="#android:Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#3892D3</item>
</style>
<!---->
<style name="MyActionBarTheme.Text" parent="#android:TextAppearance">
<item name="android:textColor">#android:color/white</item>
<item name="android:textSize">20sp</item>
</style>
<style name="TextAppearance">
<item name="android:textColor">#android:color/white</item>
</style>
</resources>
Thank you!
I've updated my SDK to API 21 and now the back/up icon is a black arrow pointing to the left.
I would like it to be grey. How can I do that?
In the Play Store, for example, the arrow is white.
I've done this to set some styles. I have used #drawable/abc_ic_ab_back_mtrl_am_alpha for homeAsUpIndicator. That drawable is transparent (only alpha) but the arrow is displayed in black. I wonder if I can set the color like I do in the DrawerArrowStyle. Or if the only solution is to create my #drawable/grey_arrow and use it for homeAsUpIndicator.
<!-- Base application theme -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle" tools:ignore="NewApi">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="homeAsUpIndicator">#drawable/abc_ic_ab_back_mtrl_am_alpha</item>
<item name="android:homeAsUpIndicator" tools:ignore="NewApi">#drawable/abc_ic_ab_back_mtrl_am_alpha</item>
</style>
<!-- ActionBar style -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="android:background">#color/actionbar_background</item>
<!-- Support library compatibility -->
<item name="background">#color/actionbar_background</item>
</style>
<!-- Style for the navigation drawer icon -->
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#color/actionbar_text</item>
</style>
My solution so far has been to take the #drawable/abc_ic_ab_back_mtrl_am_alpha, which seems to be white, and paint it in the color I desire using a photo editor. It works, although I would prefer to use #color/actionbar_text like in DrawerArrowStyle.
You can achieve it through code. Obtain the back arrow drawable, modify its color with a filter, and set it as back button.
final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
upArrow.setColorFilter(getResources().getColor(R.color.grey), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(upArrow);
Revision 1:
Starting from API 23 (Marshmallow) the drawable resource abc_ic_ab_back_mtrl_am_alpha is changed to abc_ic_ab_back_material.
EDIT:
You can use this code to achieve the results you want:
toolbar.getNavigationIcon().setColorFilter(getResources().getColor(R.color.blue_gray_15), PorterDuff.Mode.SRC_ATOP);
Looking at the Toolbar and TintManager source, drawable/abc_ic_ab_back_mtrl_am_alpha is tinted with the value of the style attribute colorControlNormal.
I did try setting this in my project (with <item name="colorControlNormal">#color/my_awesome_color</item> in my theme), but it's still black for me.
Update:
Found it. You need to set the actionBarTheme attribute (not actionBarStyle) with colorControlNormal.
Eg:
<style name="MyTheme" parent="Theme.AppCompat.Light">
<item name="actionBarTheme">#style/MyApp.ActionBarTheme</item>
<item name="actionBarStyle">#style/MyApp.ActionBar</item>
<!-- color for widget theming, eg EditText. Doesn't effect ActionBar. -->
<item name="colorControlNormal">#color/my_awesome_color</item>
<!-- The animated arrow style -->
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
</style>
<style name="MyApp.ActionBarTheme" parent="#style/ThemeOverlay.AppCompat.ActionBar">
<!-- THIS is where you can color the arrow! -->
<item name="colorControlNormal">#color/my_awesome_color</item>
</style>
<style name="MyApp.ActionBarStyle" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="elevation">0dp</item>
<!-- style for actionBar title -->
<item name="titleTextStyle">#style/ActionBarTitleText</item>
<!-- style for actionBar subtitle -->
<item name="subtitleTextStyle">#style/ActionBarSubtitleText</item>
<!--
the actionBarTheme doesn't use the colorControlNormal attribute
<item name="colorControlNormal">#color/my_awesome_color</item>
-->
</style>
Tried all suggestions above. The only way that I managed to change the color of navigation icon default Back button arrow in my toolbar is to set colorControlNormal in base theme like this. Probably due to the fact that the parent is using Theme.AppCompat.Light.NoActionBar
<style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorControlNormal">#color/white</item>
//the rest of your codes...
</style>
Need to add a single attribute to your toolbar theme -
<style name="toolbar_theme" parent="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="colorControlNormal">#color/arrow_color</item>
</style>
Apply this toolbar_theme to your toolbar.
OR
you can directly apply to your theme -
<style name="CustomTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorControlNormal">#color/arrow_color</item>
//your code ....
</style>
Just add
<item name="colorControlNormal">#color/white</item>
to your current app theme.
if use Toolbar,you can try this
Drawable drawable = toolbar.getNavigationIcon();
drawable.setColorFilter(ContextCompat.getColor(appCompatActivity, colorId), PorterDuff.Mode.SRC_ATOP);
As said on most of the previous comments, the solution is to add
<item name="colorControlNormal">#color/white</item>
to your app theme.
But confirm that you don´t have another theme defined in your Toolbar element on your layout.
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
The answer by Carles is the correct answer, but few of the methods like getDrawable(), getColor() got deprecated at the time I am writing this answer. So the updated answer would be
Drawable upArrow = ContextCompat.getDrawable(context, R.drawable.abc_ic_ab_back_mtrl_am_alpha);
upArrow.setColorFilter(ContextCompat.getColor(context, R.color.white), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(upArrow);
Following some other stackoverflow queries I found that calling ContextCompat.getDrawable() is similar to
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return resources.getDrawable(id, context.getTheme());
} else {
return resources.getDrawable(id);
}
And ContextCompat.getColor() is similar to
public static final int getColor(Context context, int id) {
final int version = Build.VERSION.SDK_INT;
if (version >= 23) {
return ContextCompatApi23.getColor(context, id);
} else {
return context.getResources().getColor(id);
}
}
Link 1: ContextCompat.getDrawable()
Link 2: ContextCompat.getColor()
I found a solution that works pre Lollipop. Set the "colorControlNormal" within the "actionBarWidgetTheme" to change the homeAsUpIndicator color. Modifying rockgecko's answer from above to look like this:
<style name="MyTheme" parent="Theme.AppCompat.Light">
<item name="actionBarTheme">#style/MyApp.ActionBarTheme</item>
<item name="actionBarStyle">#style/MyApp.ActionBar</item>
<!-- color for widget theming, eg EditText. Doesn't effect ActionBar. -->
<item name="colorControlNormal">#color/my_awesome_color</item>
<!-- The animated arrow style -->
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<!-- The style for the widgets on the ActionBar. -->
<item name="actionBarWidgetTheme">#style/WidgetStyle</item>
</style>
<style name="WidgetStyle" parent="style/ThemeOverlay.AppCompat.Light">
<item name="colorControlNormal">#color/my_awesome_color</item>
</style>
On compileSdkVersoin 25, you could do this:
styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:textColorSecondary">#color/your_color</item>
</style>
Change Menu Nav Icon Color
In style.xml :
<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="android:textColor">#color/colorAccent</item>
</style>
<style name="DrawerArrowStyle" parent="#style/Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#color/colorPrimaryDark</item>
</style>
In Mainfests.xml :
<activity android:name=".MainActivity"
android:theme="#style/MyMaterialTheme.Base"></activity>
Use below method:
private Drawable getColoredArrow() {
Drawable arrowDrawable = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
Drawable wrapped = DrawableCompat.wrap(arrowDrawable);
if (arrowDrawable != null && wrapped != null) {
// This should avoid tinting all the arrows
arrowDrawable.mutate();
DrawableCompat.setTint(wrapped, Color.GRAY);
}
return wrapped;
}
Now you can set the drawable with:
getSupportActionBar().setHomeAsUpIndicator(getColoredArrow());
Solution is very simple
Just put following line into your style named as AppTheme
<item name="colorControlNormal">#color/white</item>
Now your whole xml code will look like shown below (default style).
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#0F0F0F</item>
<item name="android:statusBarColor">#EEEEF0</item>
<item name="android:windowLightStatusBar">true</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowActivityTransitions">true</item>
<item name="colorControlNormal">#color/white</item>
</style>
Another solution that might work for you is to not declare your toolbar as the app's action bar ( by setActionBar or setSupportActionBar ) and set the back icon in your onActivityCreated using the code mentioned in another answer on this page
final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
upArrow.setColorFilter(getResources().getColor(R.color.grey), PorterDuff.Mode.SRC_ATOP);
toolbar.setNavigationIcon(upArrow);
Now, you will not get the onOptionItemSelected callback when you press the back button. However, you can register for that using setNavigationOnClickListener. This is what i do:
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
getActivity().onBackPressed(); //or whatever you used to do on your onOptionItemSelected's android.R.id.home callback
}
});
I'm not sure if it will work if you work with menu items.
This is what worked for me:
Add the below attributes to your theme.
To change toolbar/actionbar back arrow above api 21
<item name="android:homeAsUpIndicator">#drawable/your_drawable_icon</item>
To change toolbar/actionbar back arrow below api 21
<item name="homeAsUpIndicator">#drawable/your_drawable_icon</item>
To change action mode back arrow
<item name="actionModeCloseDrawable">#drawable/your_drawable_icon</item>
To remove toolbar/actionbar shadow
<item name="android:elevation" tools:targetApi="lollipop">0dp</item>
<item name="elevation">0dp</item>
<!--backward compatibility-->
<item name="android:windowContentOverlay">#null</item>
To change actionbar overflow drawable
<!--under theme-->
<item name="actionOverflowButtonStyle">#style/MenuOverflowStyle</item>
<style name="MenuOverflowStyle" parent="Widget.AppCompat.ActionButton.Overflow">
<item name="srcCompat">#drawable/ic_menu_overflow</item>
Note : 'srcCompat' is used instead of 'android:src' because of vector drawable support for api below 21
Here's how I did it in Material Components:
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="drawerArrowStyle">#style/AppTheme.DrawerArrowToggle</item>
</style>
<style name="AppTheme.DrawerArrowToggle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="color">#android:color/white</item>
</style>
We were running into the same problem and all we wanted was to set the
app:collapseIcon
attribute in the toolbar in the end, which we did not find since it is not very well documented :)
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="#dimen/toolbarHeight"
app:collapseIcon="#drawable/collapseBackIcon" />
try this
public void enableActionBarHomeButton(AppCompatActivity appCompatActivity, int colorId){
final Drawable upArrow = ContextCompat.getDrawable(appCompatActivity, R.drawable.abc_ic_ab_back_material);
upArrow.setColorFilter(ContextCompat.getColor(appCompatActivity, colorId), PorterDuff.Mode.SRC_ATOP);
android.support.v7.app.ActionBar mActionBar = appCompatActivity.getSupportActionBar();
mActionBar.setHomeAsUpIndicator(upArrow);
mActionBar.setHomeButtonEnabled(true);
mActionBar.setDisplayHomeAsUpEnabled(true);
}
function call:
enableActionBarHomeButton(this, R.color.white);
I just changed the toolbar theme to be #style/ThemeOverlay.AppCompat.Light
and the arrow became dark gray
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:gravity="center"
app:layout_collapseMode="pin"
app:theme="#style/ThemeOverlay.AppCompat.Light">
The simplest (and best) way to change the color of the back/up-arrow. Best part is
that there are no side-effects (unlike the other answers)!
Create a style with parent Widget.AppCompat.DrawerArrowToggle, define the color and any other attributes you'd like.
Set the style on the drawerArrowStyle attribute in the apps Theme.
Create style:
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<!-- Set that the nav buttons will animate-->
<item name="spinBars">true</item>
<!-- Set the color of the up arrow / hamburger button-->
<item name="color">#color/white</item>
</style>
Set the style in App Theme:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<!-- Change global up-arrow color with no side-effects -->
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
</style>
To change the ToolBar text color (and other attributes), create this style:
<style name="ToolbarStyle" parent="Widget.AppCompat.Toolbar">
<item name="android:textColor">#color/white</item>
<item name="titleTextColor">#color/white</item>
<item name="colorControlNormal">#color/white</item> <!-- colorControlNormal is Probably not necessary -->
</style>
Then set that style on the AppTheme:
<!-- Base application theme. -->
<style name="AppTheme.MyProduceApp" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<!-- Style the toolbar (mostly the color of the text) -->
<item name="toolbarStyle">#style/ToolbarStyle</item>
<!-- Change color of up-arrow -->
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
</style>
You can change the color of the navigation icon programmatically like this:
mToolbar.setNavigationIcon(getColoredArrow());
private Drawable getColoredArrow() {
Drawable arrowDrawable = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
Drawable wrapped = DrawableCompat.wrap(arrowDrawable);
if (arrowDrawable != null && wrapped != null) {
// This should avoid tinting all the arrows
arrowDrawable.mutate();
DrawableCompat.setTintList(wrapped, ColorStateList.valueOf(this.getResources().getColor(R.color.your_color)));
}
}
return wrapped;
}
private fun setToolbarNavigationIconColor(context: Context, toolbar: Toolbar?, color: Int) {
val drawableBack = toolbar?.navigationIcon
drawableBack?.let {
val drawableWrap = DrawableCompat.wrap(drawableBack).mutate()
DrawableCompat.setTint(
drawableWrap, ContextCompat.getColor(context, white)
)
toolbar.navigationIcon = drawableWrap
}
}
I saw all soluation but didn't fix the problem , If you need fix the problem just add in XMl file this code if you but dark make it light
app:theme="#style/ThemeOverlay.AppCompat.Light"
Just remove android:homeAsUpIndicator and homeAsUpIndicator from your theme and it will be fine. The color attribute in your DrawerArrowStyle style must be enough.
Unless there's a better solution...
What I did is to take the #drawable/abc_ic_ab_back_mtrl_am_alpha images, which seem to be white, and paint them in the color I desire using a photo editor.
I have different Activities in my App and in all of them I do not want the Action Bar. I cannot find how to disable it. I have tried to find an attribute to apply it to the main_activity.xml but so far I did not find anything. Can somebody help me please?
Haha, I have been stuck at that point a while ago as well, so I am glad I can help you out with a solution, that worked for me at least :)
What you want to do is define a new style within values/styles.xml so it looks like this
<resources>
<style name = "AppTheme" parent = "android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name = "NoActionBar" parent = "#android:style/Theme.Holo.Light">
<item name = "android:windowActionBar">false</item>
<item name = "android:windowNoTitle">true</item>
</style>
</resources>
Only the NoActionBar style is intresting for you. At last you have to set is as your application's theme in the AndroidManifest.xml so it looks like this
<application
android:allowBackup = "true"
android:icon = "#drawable/ic_launcher"
android:label = "#string/app_name"
android:theme = "#style/NoActionBar" <!--This is the important line-->
>
<activity
[...]
There are multiple ways of doing this.
1) Change the theme in Android Manifest
Below the Application element, you will find theme tag. Replace it with this one -
android:theme="#android:style/Theme.NoTitleBar"
If you are using AppCompat, use #android:style/Theme.AppCompat.NoActionBar.
This will set the theme for all activities. If you don't need the action bar in a specific acitivity, then set the theme in the activity container, ie
<activity android:theme="#android:style/Theme.NoTitleBar" ...>
You may also set android:theme="#android:style/Theme.NoTitleBar" theme in the styles and use it later on.
2) Create a Custom Theme
Add this in res/values/styles.xml
<style name="NoActionBar" parent="#android:style/Theme.Holo.Light">
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
and then set it as your activity's theme in Manifest:
<activity android:theme="#style/NoActionBar" ... />
3) Dynamically Remove the Action Bar
Put this code in the onCreate method before setting content view -
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();
If you are using the support library use getSupportActionBar().
If you're using AppCompat, declare your activity in AndroidManifest.xml as follows:
<activity
android:name=".SomeActivity"
...
android:theme="#style/Theme.AppCompat.Light.NoActionBar" />
Considering everyone is posting older ways of hiding the ActionBar here is the proper way of implementing it within styles for AppCompat support library. Which I highly suggest moving toward if you haven't already.
Simply removing the ActionBar
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
If you are using the appcompat support libraries, this is the easiest and recommended way of hiding the ActionBar to make full screen or start implementing to toolbar within your layouts.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Your Toolbar Color-->
<item name="colorPrimary">#color/primary</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#color/primary_dark</item>
<!-- colorAccent is used as the default value for colorControlActivated,
which is used to tint widgets -->
<item name="colorAccent">#color/accent</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight, and colorSwitchThumbNormal. -->
</style>
Then to change your toolbar color
<android.support.v7.widget.Toolbar
android:id=”#+id/my_awesome_toolbar”
android:layout_height=”wrap_content”
android:layout_width=”match_parent”
android:minHeight=”?attr/actionBarSize”
android:background=”?attr/primary” />
Last note: Your Activity class should extend AppCompatActivity
public class MainActivity extends AppCompatActivity {
<!--Activity Items -->
}
Default style you getting in res/value/style.xml like
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
And just the below like in your activity tag,
android:theme="#style/AppTheme.NoActionBar"
If you want most of your activities to have an action bar you would probably inherit your base theme from the default one (this is automatically generated by Android Studio per default):
<!-- Base application theme. -->
<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>
And then add a special theme for your bar-less activity:
<style name="AppTheme.NoTitle" parent="AppTheme">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="actionBarTheme">#null</item>
</style>
For me, setting actionBarTheme to #null was the solution.
Finally setup the activity in your manifest file:
<activity ... android:theme="#style/AppTheme.NoTitle" ... >
You may also change inheritance from ActionBarActivity to Activity as written here.
UPDATE
A good solution is here:
#Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_main);
}
open Manifest and add attribute theme = "#style/Theme.AppCompat.Light.NoActionBar" to activity you want it without actionbar :
<application
...
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
...
</activity>
</application>
I will try to show it as simple as i can:
DECLARE FULL SCREEN ACTIVITY IN ANDROID MAINIFEST file:
<activity
android:name=".GameActivity"
android:label="#string/title_activity_game"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
Now in Android studio (if you using it) open your Activity xml file ( in my example activity_game.xml) in designer and select theme (above mobile phone in designer click button with small circle) and then select Mainfest Themes on the left side and then NoTitleBar.Fullscreen.
Hope it will help!
Please find the default theme in styles.xml
<!-- Base application theme. -->
<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>
And change parent this way
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
android:theme="#style/Theme.MaterialComponents.Light.NoActionBar"
Using this theme worked for me
Put this line in your Activity in the Manifest:
<activity android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
...
</activity>
and make sure you didn't put Toolbar in your layout
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
/>
Create an new Style with any name, in my case "Theme.Alert.NoActionBar"
<style name="Theme.Alert.NoActionBar" parent="Theme.AppCompat.Dialog">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
set its parent as "Theme.AppCompat.Dialog" like in the above code
open AndoridManifest.xml and customize the activity you want to show as Alert Dialog like this
<activity
android:excludeFromRecents="true"
android:theme="#style/Theme.Alert.NoActionBar"
android:name=".activities.UserLoginActivity" />
in my app i want show my user login activity as Alert Dialog, these are the codes i used. hope this works for you!!!
It's Really Simple Just go to your styles.xml change the parent Theme to either
Theme.AppCompat.Light.NoActionBar or Theme.AppCompat.NoActionbar and you are done.. :)