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.
Related
I want to change the action bar color and text color as in Instagram. Because when I make a gray color, the icon and the time are not clear.
try using this code,
<style name="statusBarStyle" parent="#android:style/Theme.DeviceDefault.Light">
<item name="android:statusBarColor">#color/status_bar_color</item>
<item name="android:windowLightStatusBar">false</item>
its not my code and i got this from here.
According to the guidelines, Starting with Android 5.0 all Notification icons must be entirely white.
The only way to have a colored icon is to lower your targetSdkVersion to values <21, but I think you would do better to follow the guidelines and use white icons only.
If you still however decide you want colored icons, you could use the DrawableCompat.setTint method from the new v4 support library.
Background
I've made a few adjustments to my tiny app, so that it would follow the material design guidelines better.
The problem
I have a search action item, and the action bar is blue, but when clicking the search action item, I can barely see the caret (where the text is being entered).
I would like to change it, maybe to white (like the text color).
What I've tried
I've tried looking at the code of the support library, searching for a function that will allow me to customize the caret's color, but I couldn't find a working solution.
I've tried to use "searchViewStyle" as one of the theme's items, and create a new style:
<style name="AppTheme.SearchViewStyle" parent="Widget.AppCompat.SearchView">
...
But none of what I've found seem fit for this.
The weird thing is that when using "Theme.AppCompat.Light" instead of "Theme.AppCompat.Light.DarkActionBar" , the caret's color has changed (to green).
The question
How do I change the color of the text caret of the search action item (AKA SearchView) ?
EDIT: I've found out that it's possible to set "colorControlActivated" for the toolbar, as such:
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarTheme">#style/AppTheme.ActionBarTheme</item>
....
<style name="AppTheme.ActionBarTheme" parent="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="colorControlActivated">#FFffffff</item>
</style>
Seems to work, but does it affect other things, except for the caret of the search item? If so, which ones? and is it possible to affect only the caret ?
Per official design guidelines, caret should be tinted (API>21) with the reference in android:colorControlActivated (colorControlActivated through support-v7). As you discovered it is automatically tinted like so.
colorControlActivated is used by default in several widgets. As the name suggest, it will be the color of:
an activated CheckBox;
a focused EditText;
selected RadioButtons;
and so on. I can't recall all places it is used in, but if you managed to apply it to the toolbar only, it shouldn't have any other application than the widgets you put in your Menu (the SearchView for example). It could (not sure) have some impact on contextual action bars.
If you want to have full control over the caret, you could also provide your own drawable:
<item name="android:textCursorDrawable">#drawable/my_drawable</item>
This works for API>12.
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.
In my android app, in the Action Bar, next to the < image is an icon. I want to make it invisible/gone ondemand dynamically. How do I do that? The icon is actually defined as follows (this should help you realize where in the action bar I am talking about).
<style name="MyAppName.LogoTheme.LogoActionBar" parent="MyAppName.Theme.ActionBar">
<item name="android:displayOptions">showHome|homeAsUp</item>
<item name="android:icon">#drawable/my_icon</item>
I tried the following, but nothing.
this.getActionBar().setDisplayHomeAsUpEnabled(false);
this.getActionBar().setLogo(null);
this.getActionBar().setDisplayUseLogoEnabled(true);
In Java, call setDisplayShowHomeEnabled(false) and setDisplayShowTitleEnabled(false) on your ActionBar.
I am using Action Bar Sherlock for compatibility with earlier versions of Android. My objective is to not display the app title in the action bar, but to show a logo on the left and a couple of action buttons on the right. In my styles, I am using these options for the action bar:
<style name="MyActionBarStyle" parent="Sherlock.__Widget.ActionBar">
<item name="background">#drawable/toolbar</item>
<item name="displayOptions">showHome|useLogo</item>
<item name="android:background">#drawable/toolbar</item>
<item name="android:displayOptions">showHome|useLogo</item>
</style>
Everything works as hoped for on Android 2.3. On my Android 4.0.4 test phone, however, the action bar takes up the entire screen, with the app logo on the left, the action buttons on the right, but these are all centered vertically on the screen instead of residing at the top. The gradient for the toolbar, which is actually a very small pic dimensionally, occupies the entire screen (besides the status bar). The rest of the activity below the action bar is not visible.
If I remove showHome from the displayOptions above, the action bar no longer takes up the whole screen. But my logo is now gone. What do I need to do to get this working properly for Android 4?
Thanks in advance for any help.
I determined that this issue is not a problem with ActionBarSherlock, just with Android 4 in general. There seems to be a combination of options that causes this behavior to happen. I couldn't find a satisfactory solution with styles but was able to get the desired behavior in code.