How can I change the default logo icon of an ActionBar to be a custom image? Similar as how it works on Whatsapp?
The ActionBar uses the android:logo attribute of your manifest, if one is provided. That lets you use separate drawable resources for the icon (Launcher) and the logo (ActionBar, among other things).
So you should add this tag into manifest like ..
<application
android:logo="#drawable/custom_image"
Update :
You can use ActionBar.setLogo() for runtime. Two versions are there setLogo(int resId) and setLogo(Drawable logo).
Read Define custom Logo for ActionBar (different than Logo) in XML? which will help you to define some styles also.
The simplest technique is to use setIcon(R.drawable.icon_name) Similarly you can do with the Title and you can also set the date in the action bar subtitle.
ActionBar ab= getActionBar();
ab.setTitle("Aries");
ab.setSubtitle(dateFormat.format(date));
ab.setIcon(R.drawable.aries3d);
You need to customize the ActionBarSherlock. Include an xml called "styles_mytheme.xml" in values folder:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.Styled" parent="#style/Theme.Sherlock.Light">
<item name="actionBarStyle">#style/CustomActionBarStyle</item>
<item name="android:actionBarStyle">#style/CustomActionBarStyle</item>
<item name="android:actionBarItemBackground">#drawable/overflow_selector</item>
<item name="android:itemBackground">#drawable/overflow_selector</item>
<item name="android:actionBarWidgetTheme">#style/CustomActionOverflowDropDownText</item>
<item name="actionBarWidgetTheme">#style/CustomTitleColorBar</item>
<item name="android:icon">#drawable/ic_nav_home_back</item>
<item name="android:homeAsUpIndicator">#drawable/ic_nav_back</item>
<item name="icon">#drawable/ic_nav_home_back</item>
<item name="dropDownListViewStyle">#style/DropDownStyles</item>
<item name="android:dropDownListViewStyle">#style/DropDownStyles</item>
</style>
<style name="CustomActionBarStyle" parent="#style/Widget.Sherlock.ActionBar">
<!-- define background for action bar (sets default for all parts of action bar - main, stacked, split) -->
<item name="android:background">#drawable/navigation</item>
<item name="background">#drawable/navigation</item>
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<!-- Style for the color title bar -->
<style name="CustomTitleColorBar" parent="#style/TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
<item name="android:textSize">12sp</item>
</style>
<style name="CustomActionOverflowDropDownText" parent="Widget">
<item name="android:textColor">#color/white</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="#style/TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
</style>
<style name="My_Theme" parent="Theme.Sherlock">
<item name="android:popupMenuStyle">#style/MyApp.PopupMenuStyle</item>
<item name="popupMenuStyle">#style/MyApp.PopupMenuStyle</item>
</style>
<style name="MyApp.PopupMenuStyle" parent="Widget.Sherlock.ListPopupWindow">
<item name="android:popupBackground">#drawable/navigation</item>
</style>
<style name="DropDownStyles" parent="Widget.Sherlock.ListView.DropDown">
<item name="android:divider">#null</item>
<item name="android:listSelector">#drawable/overflow_selector</item>
</style>
</resources>
Now include this xml in the code:
setTheme(Theme.Styled);
Now change these three lines, when you change these three lines, the icon will change:
<item name="android:icon">#drawable/ic_nav_home_back</item>
<item name="android:homeAsUpIndicator">#drawable/ic_nav_back</item>
<item name="icon">#drawable/ic_nav_home_back</item>
if(getSupportActionBar() != null) {
getSupportActionBar().setDisplayUseLogoEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.add_contact);
}
Related
I would like to avoid applying a style to the toolbars in all layouts, so I have a style I created for it:
<style name="DarkToolbar" >
<item name="android:textColorPrimary">#color/white</item>
<item name="android:textColorSecondary">#color/white</item>
<item name="android:background">#color/blue</item>
<item name="android:elevation">4dp</item>
</style>
And I added it to my theme as follows:
<style name="Theme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/blue</item>
<item name="colorPrimaryDark">#color/blue</item>
<item name="colorAccent">#color/blue</item>
<item name="android:toolbarStyle">#style/DarkToolbar</item>
</style>
This is the resulting toolbar:
As you can see, the title and subtitle have the wrong formatting. If I remove the style from the theme and apply it directly to the toolbar in the layout, I get the following result instead:
Both images use the same style. One is applied through the app theme with
<item name="android:toolbarStyle">#style/DarkToolbar</item>
and the second one is applied directly to the toolbar with
style="#style/DarkToolbar"
Does anyone know the reason for the difference?
Also, does anyone know why the
<item name="android:textColorPrimary">#color/white</item>
<item name="android:textColorSecondary">#color/white</item>
Are not being applied?
Thanks
Add parent="Widget.AppCompat.Toolbar" to your toolbar style. It is default style for toolbar.
For example:
<style name="DarkToolbar" parent="Widget.AppCompat.Toolbar">
<item name="android:textColorPrimary">#color/white</item>
<item name="android:textColorSecondary">#color/white</item>
<item name="android:background">#color/blue</item>
<item name="android:elevation">4dp</item>
</style>
I think this has to do with
< item name="android:theme">#style/ThemeOverlay.AppCompat.Dark.ActionBar< /item>
in your style
I personally find styling toolbar text quite complicated, so mostly end up with my own TextView. How about using your own TextView inside toolbar. It would be easy, though a bit lengthy.
You are setting parent as no action bar in your theme, as this will give you the run time exception and null point exception as there is no action bar or tool bar to set the title/sub-title. Try adding parent in your theme with toolbar or action bar likes this.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="DarkToolbar">
<item name="android:textColorPrimary">#color/white</item>
<item name="android:textColorSecondary">#color/white</item>
<item name="android:background">#color/blue</item>
<item name="android:elevation">4dp</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/blue</item>
<item name="colorPrimaryDark">#color/blue</item>
<item name="colorAccent">#color/blue</item>
<item name="android:toolbarStyle">#style/DarkToolbar</item>
</style>
</resources>
I am trying to change the background color of actionbar in my App but this is showing different on my app. Instead of coloring the actionbar the whole activity is color.
I am not sure why this is happening? I just want the main actionbar and settings actionbar colored.
Please check the screenshot.
Main Activity Map:
Preference Settings:
I also have transparent Actionbar with UP Navigation enabled for all my sub activities other than the main activity and preference settings activity.
I am not sure why it is showing like the above:
Here is style.xml (values-v14):
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:background">#FF5050</item>
</style>
<style name="dialogtheme" parent="#android:style/Theme.Holo.Light.DarkActionBar"></style>
<!-- Transparent ActionBar Style -->
<style name="AppTheme.Light.ActionBar.Transparent" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#android:color/transparent</item>
</style>
<!-- Activity Theme with transparent ActionBar -->
<style name="AppTheme.TransparentActionBar.Light" parent="#style/AppBaseTheme">
<item name="android:actionBarStyle">#style/AppTheme.Light.ActionBar.Transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:displayOptions">showHome|homeAsUp|showTitle</item>
<item name="android:icon">#android:color/transparent</item>
<item name="android:actionBarTabTextStyle">#style/ActionBarTabTextStyle.Tabtheme</item>
<item name="android:actionBarDivider">#drawable/verticallinefordivder</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle.MapsLocation</item>
</style>
<style name="simpledialog" parent="android:Theme.Holo.Light.Dialog">
<item name="android:windowNoTitle">true</item>
</style>
<style name="ActionBarTabTextStyle.Tabtheme" parent="#style/AppBaseTheme">
<item name="android:textSize">18sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#android:color/black</item>
</style>
<style name="ActionBarTabStyle.MapsLocations" parent="#android:style/Widget.Holo.Light.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator</item>
</style>
<style name="myPreferenceTheme" parent="#style/AppBaseTheme">
<item name="android:textColor">#color/blue</item>
</style>
<style name="Widget.ActionButton" parent="#style/AppBaseTheme">
<item name="android:background">?android:attr/actionBarItemBackground</item>
<item name="android:paddingLeft">12dip</item>
<item name="android:paddingRight">12dip</item>
<item name="android:minWidth">56dip</item>
<item name="android:minHeight">?android:attr/actionBarSize</item>
</style>
</resources>
A little change and you action bar will be red:
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/AppTheme.Light.ActionBar</item>
</style>
<style name="dialogtheme" parent="#android:style/Theme.Holo.Light.DarkActionBar"></style>
<!-- Transparent ActionBar Style -->
<style name="AppTheme.Light.ActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#FF5050</item>
</style>
I have changed item in AppBaseTheme & AppTheme.Light.ActionBar .
Now you are good to go. let me know if it works however working at my end :P
You can try set custom view in action bar.
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(you_custom_layout);
I know this is not right answer to this question but if you want to edit your ActionBar, you can use this online Android Action Bar Style Generator.
At least you can create a style and check yours to find differences and learn how to edit your ActionBar.
What I'm trying to do is exactly as shown in the image"
I want to remove this divider. I'm using the android built-in action bar. I don't want to use Sherlock Action Bar. I have to use android action bar.
I have tried to add this to my styles but its not working
<style name="MyDropDownNav" parent="android:style/Theme.Holo.Light">
<item name="android:dropDownSelector">#drawable/ic_launcher</item>
<item name="android:divider">#null</item>
</style>
Do you have any suggestions?
You can implement a Translucent Action Bar:
Custom Translucent Android ActionBar
Show ImageView partly behind transparent ActionBar
Define themes:
<resources>
<style name="Theme.TranslucentActionBar" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/Widget.ActionBar</item>
</style>
<style name="Theme.TranslucentActionBar.ActionBar" />
<style name="Theme.TranslucentActionBar.ActionBar.Overlay">
<item name="android:actionBarStyle">#style/Widget.ActionBar.Transparent</item>
<item name="android:windowActionBarOverlay">true</item>
</style>
</resources>
and styles for your Action Bar:
<resources>
<style name="Widget.ActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/ab_background</item>
</style>
<style name="Widget.ActionBar.Transparent">
<item name="android:background">#android:color/transparent</item>
</style>
</resources>
Then apply it in your AndroidManifest.xml.
<style name="AppTheme" parent="android:Theme.whatever_theme_you_have">
...
<item name="android:windowContentOverlay">#null</item>
</style>
The divider is contained for actionbar background image.
Try to change actionbar background image. Please refer to below codes.
<style name="AppTheme">
<item name="android:actionBarStyle">#style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle">
<item name="android:background">{SET BACKGROUND FOR YOU}</item>
</style>
I am trying to change the drop down background of the sherlock action bar as well as its text color. Here's what I have tried:
<style name="DropDown" parent="Widget.Sherlock.Spinner.DropDown.ActionBar">
<item name="android:popupBackground">#EDEDED</item>
</style>
<style name="TextAppearance" parent="TextAppearance.Sherlock.Widget.TextView.SpinnerItem">
<item name="android:textColor">#A9A9A9</item>
</style>
<style name="SpinnerItemStyle" parent="Widget.Sherlock.TextView.SpinnerItem">
<item name="android:textAppearance">#style/TextAppearance</item>
</style>
<style name="MyTheme" parent="#style/devcheckStyle">
<item name="android:actionDropDownStyle">#style/DropDown</item>
<item name="actionDropDownStyle">#style/DropDown</item>
<item name="spinnerItemStyle">#style/SpinnerItemStyle</item>
<item name="android:spinnerItemStyle">#style/SpinnerItemStyle</item>
</style>
The main theme being MyTheme, with the following code I am getting the desirable background color, but I am getting nowhere with the text's color inside the drop down navigation. Can someone please help.
Put that code
<item name="android:textColor">#ffffffff</item>
into your MyTheme code should be like:
<style name="MyTheme" parent="#style/devcheckStyle">
<item name="android:actionDropDownStyle">#style/DropDown</item>
<item name="actionDropDownStyle">#style/DropDown</item>
<item name="spinnerItemStyle">#style/SpinnerItemStyle</item>
<item name="android:spinnerItemStyle">#style/SpinnerItemStyle</item>
</style>
How can I modify the style of the items on the Action bar of an Android Application?
I tryed the following:
<item name="android:actionBarStyle">#style/ActionBar.Light</item>
<style name="ActionBar.Light" parent="#style/ActionBar">
<item name="android:background">#color/black</item>
<item name="android:actionMenuTextColor">#FF00FF</item>
</style>
The background of the Action bar I was able to modify, but not the text Colors of the items in the Action bar. How can I do it?
EDIT:
I tried pretty much all the android:action attributes I found, but I couldn't manage to change anything other than the background. Only the first <item name="android:background">#FF0000</item> of the following code makes changes on my code. No matter which values I put on the Test style, it doesn't change anything. Why is it happening?
<item name="android:actionBarStyle">#style/ActionBar.Light</item>
<style name="ActionBar.Light" parent="#style/ActionBar">
<item name="android:background">#FF0000</item>
<item name="android:actionMenuTextColor">#style/Test</item>
<item name="android:actionButtonStyle">#style/Test</item>
<item name="android:actionModeBackground">#style/Test</item>
<item name="android:actionMenuTextAppearance">#style/Test</item>
</style>
<style name="Test">
<item name="android:textColor">#color/white</item>
<item name="android:background">#FF0000</item>
</style>
If you want to change the color of the menu items in the action bar you have to set the actionMenuTextColor in your theme style.
<style name="PortfolioTheme" parent="android:style/Theme.Holo.Light">
<item name="android:actionMenuTextColor">#24598a</item>
<item name="actionMenuTextColor">#24598a</item>
</style>
You don't define the menu item colors in the actionMenuTextAppearance!
You can change the color by:-
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyTheme.ActionBarStyle</item>
</style>
<style name="MyTheme.ActionBarStyle" parent="android:style/Widget.Holo.ActionBar">
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/red</item>
</style>
</resources>