This question already has an answer here:
Change Android 5.0 Actionbar color
(1 answer)
Closed 7 years ago.
I have looked through the Android examples online and perused through all the available documentation, but am still befuddled. I am targeting version 19 of the Android SDK as minSDK. All I need to do is to change the background color of the actionbar. My code for some reason does not seem to work.
I want the window background color of the rest of the app to be white.
I want the background of the actionbar to be blue.
Below is my resources file:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:windowBackground">#android:color/white</item>
<item name="android:actionBarStyle">#style/post_action_bar</item>
</style>
<style name="post_action_bar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#android:color/holo_blue_dark</item>
<item name="android:backgroundStacked">#android:color/holo_blue_dark</item>
<item name="android:backgroundSplit">#android:color/holo_blue_dark</item>
<item name="android:windowActionBar">true</item>
<item name="android:windowNoTitle">false</item>
</style>
</resources>
This does not work. The rest of the app is white, but my bar has a grayish color.
You can try to set programatically in code like
ActionBar ab = getActionBar();
ab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#000000")));
It's as easy as adding this to your AppTheme
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#color/my_awesome_color</item>
Note: this will work pre-lolipop as long as your theme's parent is from Theme.AppCompat and your support library is atleast v21, so if you havent already update the support lib to the latest which at this time is v23.0.1 (i think)
compile 'com.android.support:appcompat-v7:23.0.1'
Read this if you want to learn more about styling your ActionBar, and more
https://developer.android.com/training/basics/actionbar/styling.html
Here you have everything explained in detail about styling the Action Bar.
Best regards
I am using theme as:
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat">
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
</style>
I want to show the ImageView partly behind the the ActionBar. I have tried Show ImageView partly behind transparent ActionBar and searched on google, but can't find the appropriate solution.
Better use Toolbar or Support Toolbar
With Toolbar, you can add it in your XML File just like any other View.
In your Activitys onCreate call setActionBar(toolbar) / setSupportActionBar(toolbar)
Or try to add these two lines in your style:
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
But using the Toolbar is actually pretty simple and the new standard.
Read this to get started: http://android-developers.blogspot.de/2014/10/appcompat-v21-material-design-for-pre.html
I want to remove the shadow from the ActionBar and I read you do this:
getSupportActionBar().setElevation(0)
However this didn't seem to work on Pre 5.0 devices. Is that a bug? I am not using the Toolbar. Just regular ActionBar from the library.
If you are using the ActionBar (not the Toolbar) you should be able to remove the shadow below using this style:
<style name="MyAppTheme" parent="Theme.AppCompat.Light">
<item name="android:windowContentOverlay">#null</item>
</style>
i am using ActionBar to create an android app in eclipse with Tab Navigations and i would like to customize each of my tabs separately to add custom background color and icon to them. How can i set background, and icon to a tab on the ActionBar?
Thanks in advance!
When you create a new Android project/Android Activity, there are some templates you can choose from. Once of those should be for a tabbed navigation activity using ActionBar tabs. Somewhere in the generated code you'll see it's creating instances of ActionBar.Tab and adding them to the ActionBar. You can call setIcon() on the ActionBar.Tabs.
For theme customization, I recommend you use this website, it will generate all the necessary drawables and xml resources, and you can just drop those all into your project. ActionBar Style Generator
I just found a workaround for this problem. I'm still unable to customize each tab separately, but i can load a drawable background to the Navigation Tab Bar in the XML;
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="android:Theme.Light">
<item name="android:backgroundStacked">#drawable/tab_bg</item>
<item name="android:height">60dp</item>
</style>
The result is the following, which is exactly what i wanted;
http://i.imgur.com/DB9LRwD.png
I'm looking through the Holo.Light theme, and I can't seem to find the magic style to override to get rid of the title text that briefly shows up when my app first launches.
How can I do that?
Try:
getActionBar().setDisplayShowTitleEnabled(false);
For v.7:
getSupportActionBar().setDisplayShowTitleEnabled(false);
I think this is the right answer:
<style name="AppTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>
<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="android:displayOptions">showHome|useLogo</item>
<item name="displayOptions">showHome|useLogo</item>
</style>
I'm very new to Android so correct me if I'm wrong, but I think if you decide to use navigation tabs on the Action Bar, they seemed to not be completely left aligned because the title text color is only transparent and hasn't gone away.
<style name="CustomActionBarStyle" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:displayOptions">useLogo|showHome</item>
</style>
worked for me.
Got it. You have to override
android:actionBarStyle
and then in your custom style you have to override
android:titleTextStyle
Here's a sample.
In my themes.xml:
<style name="CustomActionBar" parent="android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/CustomActionBarStyle</item>
</style>
And in my styles.xml:
<style name="CustomActionBarStyle" parent="android:style/Widget.Holo.ActionBar">
<item name="android:titleTextStyle">#style/NoTitleText</item>
<item name="android:subtitleTextStyle">#style/NoTitleText</item>
</style>
<style name="NoTitleText">
<item name="android:textSize">0sp</item>
<item name="android:textColor">#00000000</item>
</style>
I'm not sure why setting the textSize to zero didn't do the trick (it shrunk the text, but didn't make it go away), but setting the textColor to transparent works.
In your Manifest
<activity android:name=".ActivityHere"
android:label="">
Write this statement under
setContentView(R.layout.activity_main);
getSupportActionBar().setDisplayShowTitleEnabled(false);
if extending AppCompactActivity use getSupportActionbar() if extending Activity use getActionBar() else it may give
null pointer exception
using android:label="" in AndroidManifest.xml for activity also works but your app won't appear in Recently used apps
you have two choice:
first:
getActionBar().setDisplayShowTitleEnabled(false);
If usign getActionBar() produced null pointer exception, you should use getSupportActionBar()
Second
getSupportActionBar().setTitle("your title");
or
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().hide();
You can change the style applied to each activity, or if you only want to change the behavior for a specific activity, you can try this:
setDisplayOptions(int options, int mask) --- Set selected display
or
setDisplayOptions(int options) --- Set display options.
To display title on actionbar, set display options in onCreate()
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);
To hide title on actionbar.
getSupportActionBar().setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
Details here.
i use this code in App manifest
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:logo="#drawable/logo2"
android:label="#string/title_text"
android:theme="#style/Theme.Zinoostyle" >
my logo file is 200*800 pixel
and use this code in main activity.java
getActionBar().setDisplayShowTitleEnabled(false);
it will work Corectly
I tried this. This will help -
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar should be called after setSupportActionBar, thus setting the toolbar, otherwise, NullpointerException because there is no toolbar set.
Hope this helps
The only thing that really worked for me was to add:
<activity
android:name=".ActivityHere"
android:label=""
>
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().hide();
hope this will help
If you only want to do it for one activity and perhaps even dynamically, you can also use
ActionBar actionBar = getActionBar();
actionBar.setDisplayOptions(actionBar.getDisplayOptions() ^ ActionBar.DISPLAY_SHOW_TITLE);
as a workaround just add this line incase you have custom action/toolbars
this.setTitle("");
in your Activity
Use the following:
requestWindowFeature(Window.FEATURE_NO_TITLE);
While all of these are acceptable, if your activity only contains a main activity, you can edit res\values\styles.xml like so:
<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>
I've updated parent and added the .NoActionBar property to the Light theme from Android Studios Create Blank Application Wizard.
Simply extends your java file from AppCompatActivity and do this:
ActionBar actionBar = getSupportActionBar(); // support.v7
actionBar.setTitle(" ");
In your manifest.xml page you can give address to your activity label. the address is somewhere in your values/strings.xml . then you can change the value of the tag in xml file to null.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title_main_activity"></string>
</resources>
I am new to Android so maybe I am wrong...but to solve this problem cant we just go to the manifest and remove the activity label
<activity
android:name=".Bcft"
android:screenOrientation="portrait"
**android:label="" >**
Worked for me....
I remove the default appbar and run a custom toolbar instead using Theme.AppCompat.Light.NoActionBar then add a textview or something that extend to full toolbar width using attribute layout_width=match_parent and it pushes the title out of the toolbar. If you want to do this, you must study how to make a toolbar.
ActionBar actionBar = getActionBar();
actionBar.setTitle("");