I implemented a theme for my ActionBar:
<style name="MyTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">#color/actionbar_background</item>
<item name="android:displayOptions">useLogo|showHome</item>
<item name="android:logo">#mipmap/ic_launcher</item>
<item name="logo">#mipmap/ic_launcher</item>
<item name="background">#color/actionbar_background</item>
</style>
And I applied it in AndroidManifest.xml:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/MyTheme">
...
I know that my theme works as I see a color change, however my actionbar icon never shows up. I see it only when I explicitly call this code in onCreate method of my activity:
ActionBar actionBar = getSupportActionBar();
actionBar.setLogo(R.mipmap.ic_launcher);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
I feel like it's not correct to copy-paste the same code for every activity. Please help me to solve this problem.
The new compat library doesn't use logos nor app icons in the Toolbar (former ActionBar). You should check the style guides about that: https://www.google.com/design/spec/layout/structure.html#structure-toolbars
Starting with lollipop you get new features like tinting the notification bar on this screen:
A cool new feature is that tinting which can color all ui elements like you need it for your branding.
It is better to use android.support.v7.widget.Toolbar , you can setup your app's action bar as follows:
Toolbar toolbar = (Toolbar) findViewById(R.id.apptoolbar);
setSupportActionBar(toolbar);
toolbar.setNavigationIcon(R.drawable.your_app_logo);
for more info you can read at Structure Of App Bar(which was called as ActionBar)
I'm trying to display a custom icon in the ActionBar, but it doesn't work.
I've tried it both programmatically with
getSupportActionBar().setIcon(R.drawable.forum_logo);
and
getSupportActionBar().setLogo(R.drawable.forum_logo);
and in AndroidManifest.xml with
android:logo="#drawable/forum_logo"
However, none of the two works. forum_logo.png is an image file of 24x24.
Other methods such as
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle((currentSubforum.getTitle()));
works as intended.
I'm using android.support.v7.app.ActionBarActivity and each Activity extends ActionBarActivity.
The android:icon attribute in AndroidManifest is already linked at a different drawable and the android:theme is "Theme.AppCompat.Light.DarkActionBar"
The answer with the Toolbar was correct, however was missing one crucial detail.
If you use a Toolbar, your theme must have the ActionBar disabled. There's a specific theme for that:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
Now in your onCreate set the Toolbar like this:
Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
toolbar.setLogo(R.drawable.ic_launcher);
setSupportActionBar(toolbar);
Note that you should use the support Toolbar: import android.support.v7.widget.Toolbar;
The Toolbar in your layout would look like this:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="65dp"
android:background="#40ffffff"/>
That being said, I found it really weird not being able to display the app icon with ActionBarActivity. Hopefully there's another way around this.
After Fragment.onActivityCreated(...) you'll have a valid activity accessible through getActivity(). You'll need to cast it to an ActionBarActivity then make the call to getSupportActionBar().
((ActionBarActivity)getActivity()).getSupportActionBar().setSubtitle(R.string.subtitle);
You do need the cast. It's not poor design it's backwards compatibility.
in the manifest use your costume theme.
<application
android:name="com.example.ifis.MyApplication"
android:allowBackup="true"
android:icon="#drawable/ifis_logo"
android:label="#string/app_name"
android:theme="#style/MyTheme" >
customize your theme in the style folder as below and add your icon to the icon
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/ifisGreen</item>
<item name="android:icon">#drawable/your_logo</item>
<item name="android:textColor">#color/ifisGreen</item>
<item name="android:height">30dp</item>
</style>
ActionBar actionBar = getActionBar();
actionBar.setIcon(R.drawable.ic_action_video);
actionBar.setDisplayShowTitleEnabled(true);
Only use 3 things..
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'm using navigation drawer in my application. I want to get rid of the android's robot icon from the action bar. I'm using the following lines but the logo is not disappearing.
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
Can anyone suggest me what should I do?
getActionBar().setLogo(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
Works as well.
Just add this to your activity
getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
to hide the logo add below line also
actionBar.setDisplayShowHomeEnabled(false);
See this link also Android remove app icon action bar
This will done the magic:
1.) Add the following lines into your styles.xml:
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/AppTheme.ActionBar</item>
</style>
<style name="AppTheme.ActionBar" parent="android:Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:displayOptions">showHome|homeAsUp|showTitle</item>
<item name="android:icon">#android:color/transparent</item>
</style>
...
2.) And don't forget to add your style into your AndroidManifest.xml (if you haven't already done it):
<application
android:theme="#style/AppTheme"
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
...
Hope this helps!
I am using a titlebar with a background image in my android app.
values/custom_styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TitlebarBackgroundStyle">
<item name="android:background">#drawable/titlebar</item>
</style>
<style name="Theme.MyCustomTheme" parent="android:Theme">
<item name="android:windowTitleBackgroundStyle">#style/TitlebarBackgroundStyle</item>
<item name="android:windowTitleSize">45dp</item>
</style>
</resources>
layout/titlebar.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:gravity="center_vertical">
<ImageView
android:id="#+id/header"
android:src="#drawable/titlebar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Manifest:
<application android:icon="#drawable/icon" android:label="#string/app_name" android:theme="#style/Theme.MyCustomTheme">
This works pretty well so far.
The only thing I'd like to do now is to hide the text on the titlebar ...
I tried:
<item name="android:textSize">0dp</item>
but with no luck. Is there any way to set the transparency or some other property that would allow me to see the background image but not the text?
thanks for your thoughts
Ron
If you are working on API level 11 or above than do this in your activity
final ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
Or you can do this by applying custom style to your activity like
<style name="CustomWindowTitle" parent="android:TextAppearance.WindowTitle">
<item name="android:visibility">gone</item>
</style>
<style name="MainTheme" parent="#android:Theme">
<item name="android:windowTitleStyle">
#style/CustomWindowTitleText</item>
</style>
And then add it to your activity like
<activity
......
android:theme="#style/MainTheme"/>
You can do it in Java, not resource xml, since the TextView on the title bar is determined programmatically by some lines in the Android Java source code.
You can hide the title bar's TextView in this way :
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
root = (LinearLayout) decorView.getChildAt(0);
FrameLayout titleContainer = (FrameLayout) root.getChildAt(0);
TextView title = (TextView) titleContainer.getChildAt(0);
title.setVisibility(View.GONE);
}
I'm not sure, but you can also try to declare your activities without label in manifest.
<activity android:name="...">
Add this to your manifest
<application android:label="bla bla"
android:icon="#drawable/bla bla"
---> android:theme="#android:style/Theme.NoTitleBar">
Try to set an empty custom titlebar with an empty layout.
Boolean customTitle = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.listviewoffers);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebarlayout);
Fortunately the way is too simple (I guess you do have a custom layout for your title)
If you don't know to do how please take a look: How to Create Custom Window Title in Android
Hiding the default title text is one line of code. Just write setTitle(""); inside onCreate().
That's it! Hope this helps!
Set your theme to a custom theme for the activity. The theme would look like this:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.Black.OptionalActionBar" parent="#android:style/Theme.Black.NoTitleBar">
<item name="android:windowNoTitle">false</item>
<item name="android:windowActionBar">true</item>
<item name="android:actionBarStyle">#style/MyActionBarStyle</item>
</style>
<style name="MyActionBarStyle" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:displayOptions">showHome</item>
</style>
<style name="OptionalVisibility">
<item name="android:visibility">invisible</item>
<item name="android:height">1dp</item>
</style>
</resources>
The ActionBarStyle overrides the behavior of the action bar. Notice I set the style to the holo actionbar and then change the displayOptions to showHome. This will only show the home icon. You can also set it to showTitle which will only show the text. Or both showHome|showTitle. If you leave it blank, <item name="android:displayOptions"></item> then the text and icon will go away all together.
NOTE: I know this will work for 3.0 (api 11) and above...I am not certain if it will work for lower API levels.
I know this is years old...but posting for others who encounter this problem.
android:theme="#android:style/Theme.NoTitleBar">
adding this in your manifest file works..
android:label=""
add this to manifest