Define custom Logo for ActionBar (different than Logo) in XML? - android

I want to make a Actionbar_style.xml for my app and I would like to use a logo, different than my app logo / icon.
How to change it programmatcially is clear: Change logo that appears in Android ActionBar programatically
But like this I would need to code this into each activity.
Is there a xml tag to define a custom Actionbarlogo in xml already?
my Customstyles.xml
<style name="CustomActionBar0" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/action_bg0</item>
</style>
android styles.xml seems not to have it...
<style name="Widget.ActionBar">
<item name="android:background">#android:drawable/action_bar_background</item>
<item name="android:displayOptions">useLogo|showHome|showTitle</item>
<item name="android:divider">#android:drawable/action_bar_divider</item>
<item name="android:height">?android:attr/actionBarSize</item>
<item name="android:paddingLeft">0dip</item>
<item name="android:paddingTop">0dip</item>
<item name="android:paddingRight">0dip</item>
<item name="android:paddingBottom">0dip</item>
<item name="android:titleTextStyle">#android:style/TextAppearance.Widget.ActionBar.Title</item>
<item name="android:subtitleTextStyle">#android:style/TextAppearance.Widget.ActionBar.Subtitle</item>
<item name="android:progressBarStyle">#android:style/Widget.ProgressBar.Horizontal</item>
<item name="android:indeterminateProgressStyle">#android:style/Widget.ProgressBar.Small</item>
<item name="android:homeLayout">#android:layout/action_bar_home</item>
</style>

Just set a value for the android:icon attribute
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/AppTheme.ActionBarStyle</item>
</style>
<style name="AppTheme.ActionBarStyle" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/actionbar_background</item>
<item name="android:titleTextStyle">#style/AppTheme.ActionBar.TitleTextStyle</item>
<item name="android:icon">#drawable/ic_home</item>
<item name="android:indeterminateProgressStyle">#style/IndeterminateProgress</item>
</style>

You don't style the logo in the your style XML, you simply use android:logo in your Manifest, then use setDisplayUseLogoEnabled() to set it in the ActionBar. Here's a project, from Google, that shows you how to switch between the two. http://code.google.com/p/styled-action-bar/

Sounds like you need to use a custom layout for the action bar, that way you can define a whatever you want for logo image.
Action bar / ActionbarSherlock style
<style name="ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="displayOptions">showCustom</item>
<item name="android:displayOptions">showCustom</item>
<item name="customNavigationLayout">#layout/action_bar_home_icon_default</item>
<item name="android:customNavigationLayout">#layout/action_bar_home_icon_default</item>
</style>
#layout/action_bar_home_icon_default is your custom layout, with your custom logo

Yes. You may set different logo for different activities. Here is the sample code in manifest file.
<activity
android:name="MyActivity"
***android:icon="#drawable/logo"***
android:label="#string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait" />
Hope this help. Cheers!

Related

Base.Widget.Design.TabLayout does not work as a parent in style.xml in android

I searched google but can not find solution.I need to define different styles for Tablayout for themes.I figure it out how to include my Toolbar style but can not make it work because of Base.Widget.Design.TabLayout.When I define it as a name it works but I can only use it for one style.When I define it as parent and include it to my theme with android:tabWidgetStyle it does not work
As a parent(which does not work)
<style name="tabayout" parent="Base.Widget.Design.TabLayout">
<item name="tabSelectedTextColor">#color/white</item>
<item name="tabIndicatorColor">#color/deep_orange_300_colorAccent</item>
<item name="tabBackground">#color/deep_orange_300_colorAccent</item>
</style>
Second(which works but I can only use it once, but I need to define 14 style)
<style name="Base.Widget.Design.TabLayout" parent="android:Widget">
<item name="tabSelectedTextColor">#color/white</item>
<item name="tabIndicatorColor">#color/red_200_colorAccent</item>
<item name="tabBackground">#color/red_200_colorAccent</item>
<item name="tabTextColor">#color/red_200_colorPrimaryDark</item>
</style>
Edit
I want to style TabLayout for specific custom theme.I want to make Toolbar background textColor etc for chosen colour by user. So I used Base.Widget.Design.TabLayout as a name to style TabLayout and include it with android:tabWidgetStyle it worked.But when I use it as parent it does not work.Here My Theme
This works.But when I define Base.Widget.Design.TabLayout as a parent it does not work.
<style name="AppTheme_red_200" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/red_200_colorPrimary</item>
<item name="colorPrimaryDark">#color/red_200_colorPrimaryDark</item>
<item name="colorAccent">#color/red_200_colorAccent</item>
<item name="android:tabWidgetStyle">#style/Base.Widget.Design.TabLayout</item>
<item name="android:textColor">#color/red_400_colorPrimaryDark</item>
</style>
<style name="Base.Widget.Design.TabLayout" parent="">
<item name="tabSelectedTextColor">#color/white</item>
<item name="tabIndicatorColor">#color/red_200_colorAccent</item>
<item name="tabBackground">#color/red_200_colorAccent</item>
<item name="tabTextColor">#color/red_200_colorPrimaryDark</item>
</style>

Set text size of menu items in popup menu

I have created options using customized popup menu.
Now, I want to set the text size of menu items. I am getting default text size this time.
How can I achieve this? I don't want to use popup window. Is it possible to achive this using popup menu only?
I had the same problem. You can change the text size and color by adding this code to styles.xml and use it in manifest file. For me it worked.
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:popupMenuStyle">#style/PopupMenu</item>
<item name="android:textAppearanceLargePopupMenu"> #style/myPopupMenuTextAppearanceLarge</item>
<item name="android:textAppearanceSmallPopupMenu"> #style/myPopupMenuTextAppearanceSmall</item>
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="PopupMenu" parent="#android:style/Widget.PopupMenu">
<item name="android:popupBackground">#android:color/white</item>
<item name="android:textColor">#FF01F0</item>
<item name="android:textSize">12sp</item>
</style>
<style name="myPopupMenuTextAppearanceSmall" parent="#android:style/TextAppearance.DeviceDefault.Widget.PopupMenu.Small">
<item name="android:textColor">#545656</item>
<item name="android:textSize">15sp</item>
</style>
<style name="myPopupMenuTextAppearanceLarge" parent="#android:style/TextAppearance.DeviceDefault.Widget.PopupMenu.Large">
<item name="android:textColor">#545656</item>
<item name="android:textSize">25sp</item>
</style>
You can use something like the below in the manifest file
<activity
android:name=".ActivityName"
android:theme="#style/styleName"/>

Change color title bar

I want to change the color of the title bar. I tried this:
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle">#style/ColorBar</item>
</style>
<style name="ColorBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/white</item>
<item name="android:textColor">#color/orange</item>
</style>
But it doesn't work. What is wrong in my code shown above?
EDIT : it's the color of the text i want to change, not the background (it's running for the background)
This should work for all devices, you will need the support library (appcompat_v7)
<style name="Theme" parent="#style/BaseTheme"></style>
<style name="BaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/ActionBar</item>
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
<style name="ActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">#color/orange </item>
<item name="background">#color/orange </item>
<item name="android:titleTextStyle">#style/ActionBar.Text</item>
<item name="titleTextStyle">#style/ActionBar.Text</item>
</style>
<style name="ActionBar.Text" parent="#android:style/TextAppearance.Medium">
<item name="android:textColor">#color/orange</item>
</style>
manifest :
android:theme="#style/Theme"
There may be problem with the android version. You should consider old ones and new ones. Try adding these both lines for different versions.
<item name="android:background">#drawable/your_color</item>
<item name="background">#drawable/your_color</item>
Does changing the parent to parent="#android:style/Widget.Holo.Light.ActionBar.Solid" make a difference?
If not, let me know what happens if you move the
<item name="android:actionBarStyle">#style/ColorBar</item> into the AppBaseTheme style
Try setting all of these:
<item name="android:background">#color/something</item>
<item name="android:backgroundStacked">#color/something</item>
<item name="android:backgroundSplit">#color/something</item>
This is an easy way for settings the color of the actionbar-title by Java
getActionBar().setTitle(Html.fromHtml("<font color=\"#ffffff\">" + "TITLE" + "</font>"));
If you're using a support library, then you can use getSupportActionBar();.
I'm new to all of this but I found it easier to go to Res > Value > colors.xml and from there you can change the "primary color." This changed the title bar to the color I selected.

Where to add custom sherlock bar custom theme for actionbar?

i would like to customize sherlock action bar (background color, font color, etc..).
I found some useful links here on stack overflow, but i dont know, where to put my new theme xml config file and how link them from AndroidManifest?
Thanks for any help.
You have to add in style like this
<style name="Theme.MyApp.Default" parent="#style/Theme.Sherlock.Light">
<item name="actionBarStyle">#style/MyApp.SherlockActionBarStyle</item>
<item name="android:actionBarStyle">#style/MyApp.kActionBarStyle</item>
</style>
<style name="MyApp.ActionBarStyle" parent="#style/Widget.Sherlock.ActionBar">
<item name="android:background">#ff000000</item>
<item name="background">#ff000000</item>
<item name="android:textSize">#dimen/textsize</item>
<item name="textSize">#dimen/textsize</item>
<item name="android:textColor">#color/grey</item>
<item name="textColor">#color/grey</item>
</style>

ActionBar custom title as ImaveView instead of TextView

I've trying to work around this on the actionbar but from What I can see the title is basicly a TextView but I need to place an image instead of plain text. I try to set it up into the Style themes.xml as this:
<item name="android:actionBarStyle">#style/MyActionBar</item>
And then I defined this style
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/action_background</item>
<item name="android:titleTextStyle">#style/ActionbarTitleStyle</item>
</style>
I thought that I could defined the background for the title but even If I do is not what I want, try the getActionBar().setCustomView(layout); but happend that my actionbar is null before the setContentView is being called and I need it in a Base class.
PD. I only need to care about HONEYCOMB and Higher, so if you please not suggest Sherlock or Jonhanilson implementations.
if you want an image, you can specify the app logo along with the icon (it will be used instead of icon):
<application
android:icon="#drawable/ic_launcher"
android:logo="#drawable/logo"
android:label="#string/app_name"
android:name=".AppName"
>
Now you have an arbitrary image instead of your lanucher icon. What you need to do next is to get rid of the text. In your styles do something like:
<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="titleTextStyle">#style/NoTitleText</item>
<item name="android:titleTextStyle">#style/NoTitleText</item>
<item name="subtitleTextStyle">#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>
You should use both item name="titleTextStyle" and item name="android:titleTextStyle" if you use ActionBarSherlock if I remember well.
Override setContentView like this:
#Override
public void setContentView(int resLayoutId) {
super.setContentView(resLayoutId);
// TODO Set your actionbar changes here
}
OR, you can do this:
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/action_background</item>
<item name="android:titleTextStyle">#style/ActionbarTitleStyle</item>
<item name="android:displayOptions">showCustom</item>
<item name="android:customNavigationLayout">#layout/custom_nav_layout</item>
</style>

Categories

Resources