Logo in ActionBar instead of text - android

I want to put a picture on my action bar, instead of the text (No, I am not using action bar sherlock), and if possible for the action bar to be transparrent AND with detectable height (I have done transparent action bar before, but you can't get its height programatically this way).
It should be in styles somehow, not programatically. Right now I have this styles.xml and it does absolutely nothing...
<resources>
<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:icon">#drawable/img_ab_youlocal_logo</item>
</style>
P.S. YES, I have searched before asking, the other asnwers were not helpful.

If you are using an api < 21 you could do something similar this:
ActionBar actionbar = getActionBar();
actionbar.setDisplayShowCustomEnabled(true);
actionbar.setCustomView(R.layout.someLayoutfile);
You may have to this before the Parent View gets inflated / set via setContentView();
Also in api > 11 you have a logo attribute:
Using a logo instead of an icon
By default, the system uses your application icon in the action bar, as specified by the icon attribute in the
<application> or <activity>
element. However, if you also specify the logo attribute,
then the action bar uses the logo image instead of the icon.
A logo should usually be wider than the icon, but should not include unnecessary text.
You should generally use a logo only when it
represents your brand in a traditional format that users recognize. A
good example is the YouTube app's logo—the logo represents the
expected user brand, whereas the app's icon is a modified version that
conforms to the square requirement for the launcher icon.

Related

how to customize app title in collapsed (for example: center or right align)

I can customize my Actionbar. But I can't customize it when the app is collapsed.
How to customize the app title when the app is collapsed (for example: center or right align)?
The color of the app bar in multitasking mode I believe is defined by the android:colorPrimary (or colorPrimary if you're using AppCompat) attribute in your styles.
I don't think you can change the alignment of the text of the app bar though.

How to customize preferences screen title in Lollipop?

I make an Android application trying to support Android Lollipop and previous versions. So, I use Theme.AppCompat.Light for my app.
In Android 4.4, Action Bar title is white like I want and preferences screen titles are blacks.
In Android 5.0, Action Bar title is black by default and preferences screen titles are blacks. But, I want my Action Bar title be white on all versions of Android so I used the following customization in my theme for v21 :
<item name="android:textColorPrimary">#android:color/white</item>
With this customization, Action Bar title is white like i want but it seems that preferences screen title are also linked to android:textColorPrimary in Android 5.0 .
So, my question is the following. Is there a solution to create an Action Bar title with white title and in the same time have preferences screen title with other color like black?
Just make two styles.
One with:
<item name="android:textColorPrimary">#android:color/white</item>
One with:
<item name="android:textColorPrimary">#android:color/black</item>
Set your activities with action bars to the white one.
Set you preference activity to the black one.

Android KitKat : All my app content appears behind the ActionBar and StatusBar after changing StatusBar color

I've created a separate xml style file targeting KitKat and I've managed to change the color of the status bar. The only side-effect as seen on the picture, all the content is now moved up beneath the status bar. My question is how can I change the color of the status bar without overlaying this or how can I know the exact top margin I need to put on my content so its starts after the ActionBar and not beneath. Of course I need this to behave as expected on all screen sizes and densities. Thank you
values-v19/styles.xml
<style name="ThemeSelector" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
You should add the following to the top of the view(s)
android:paddingTop="?android:attr/actionBarSize"
If you're using the Support Library for the action bar, you need to remove the android: prefix
android:paddingTop="?attr/actionBarSize"
By enabling translucent system bars, your layout will fill the area behind the system bars, so you must also enable fitsSystemWindows for the portion of your layout that should not be covered by the system bars.
EDITED
You can add
android:fitsSystemWindows="true"
in your XML File
Remove from your layout
android:fitsSystemWindows="true"

Action bar action button icon size

Our app uses Action Bar Sherlock, and it has a theme like such:
<style name="Theme.MyApp.Default" parent="#style/Theme.Sherlock.Light">
<item name="actionButtonStyle">#style/MyApp.SherlockActionBar.Light.ActionButton</item>
<item name="android:actionButtonStyle">#style/MyApp.SherlockActionBar.Light.ActionButton</item>
</style>
<style name="MyApp.SherlockActionBar.Light.ActionButton" parent="#style/Widget.Sherlock.Light.ActionButton">
<item name="android:maxHeight">20dp</item>
<item name="android:maxWidth">20dp</item>
</style>
Where Theme.MyApp.Default is the default theme for the app.
I need to set the icons for the action buttons (#2 on this image) to be a specific size. When I set the height/width/scaleX/scaleY/scaleType/padding properties however, the icon on the button still maintain what looks like their pixel size. The text part of the action button does seems to adhere to the setting though. Could it just be a compound drawable on a textview?
How can I set the size of the icon on the action bar?
Action bar icons for phones should be 32x32 dp.
Action bar icons are graphic buttons that represent the most important actions people can take within your app. Each one should employ a simple metaphor representing a single concept that most people can grasp at a glance.
you refer that link here
Have you cleaned your project and then run?
and you can specify action item height in main.xml(actionbar menu layout ) also though contrl space wont wrk its like normal height prperty.
whenever changing styles you have to clean and run the project
More and more evidence points to the fact that the menu on the action bar is a compound drawable. (Setting the property android:drawablePadding moves the icon from the text.) And seeing that you can't scale the image in XML for a compound drawable, this doesn't seem possible at the moment.

ActionBar - Using a View as icon

So, I want to use a View in place of the app icon in the actionbar. I can't use a simple image because the View will change its colours depending of the set of colors chosen in the parameters of the app (and I don't want to create four hundred images in photoshop...).
I know I can use a custom view for the action bar and it's even quiet easy, but the problem is that the original app image is still shown. I also know that I can hide it by setting setDisplayShowHomeEnabled to false, but that also hides the glyph of my navigation drawer and that is the problem.
I also tried to create a custom Drawable and override the onDraw method but nothing was shown and the Drawable has 1px height/width.
To hide the icon you can use a transparent one, edit the style you use for your actionbar like this :
<style name="MyActionBarStyle" parent="#style/Widget.Sherlock.Light.ActionBar">
<item name="icon">#android:color/transparent</item>
</style>
assuming you use as style named MyActionBarStyle for your actionbar in your theme.
<style name="AppBaseTheme" parent="#style/Theme.Sherlock.Light">
<item name="actionBarStyle">#style/MyActionBarStyle</item>
</style>

Categories

Resources