Is there a way to provide a different drawable icon if menu items are pushed to the split actionbar? My split action bar color differs to much from the top bar and a single icon style is not as visually please as I would hope.
Put the Drawables that you want to use for split in /res/drawable/ and put the others in /res/drawable-w480dp.
You can use LevelListDrawable for the icons and set the level when the screen configuration changes (which means Activity.onCreate()is called.
Create a drawable to be used in the icons with
<level-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:maxLevel="0" android:drawable="#drawable/**your bitmap dark**" />
<item android:maxLevel="1" android:drawable="#drawable/**your bitmap light**" />
</level-list>
Detect, if ActionBar is splitted or not. This part seems to be tricky. I'm using SherlockActionBar and there it works (up to todays Android Version) this way
To change one drawable, set on the corresponding ActionBar.Tab the level with getIcon().setLevel(). Note that you do not need to cast to LevelListDrawable. For whatever reason the level concept is implemented directly with the Drawable class.
In the appcompat library the split ActionBar is used in configurations other than large, land or sw480dp. If youre using the native ActionBar i guess you can skip the large configuration.
Then, to provide alternative drawables you should define appropriate references in these values dirs, like:
In values:
<item name="action_search_drawable" type="drawable" format="reference">#drawable/ic_action_search_narrow</item>
In values-w480dp:
<item name="action_search_drawable" type="drawable" format="reference">#drawable/ic_action_search</item>
Then, in the menu configuration you should use this reference as the icon drawable.
Related
I was just wondering about tabs that change color when you are on the selected fragment
For example:
like facebook app tabs, when you are on home page the icon color changes to blue.
Is this a tool or library used, or just i have to explicitly change all colors when fragment change ?
Try out bottom navigation view (https://developer.android.com/reference/android/support/design/widget/BottomNavigationView) by android and use a color selector like
background_color.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="#color/blue" />
<item android:color="#color/grey" />
</selector>
and use this as
app:itemIconTint="#color/background_color.xml"
in your bottom navigation view.
It's hard to say exactly how any given app does that, but chances are good they are using a Color State List resource or a State List Drawable resource. Such a resource allows you to define different values for different "states" all within a single file. Then you can apply this resource to your tabs (or checkbox or anything else) and it will automatically update accordingly.
I am new to Android, and before starting programming i found that now a days many of the apps are using Fragments, especially Tab with Swipeable Views
How to change Tab Indicator/highlight color (I googled and changed ActionBar color to RED programmatically), but don't know how to change Tab Indicator color to RED.
(priority programmatically)
still my ActionBar looks like this
I am using below lines to change background color of ActionBar, but i also need to change the color of Tab Indicator programmatically.
actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.RED));
I use Jeff Gilfelt,s Android Action Bar Style Generator. You can use GUI to style your tabs and at the end you get the source code which you can use, review and modify accordingly. :)
Here's a link.
http://jgilfelt.github.io/android-actionbarstylegenerator/#name=example&compat=holo&theme=light&actionbarstyle=solid&texture=0&hairline=0&neutralPressed=1&backColor=E4E4E4%2C100&secondaryColor=D6D6D6%2C100&tabColor=33B5E5%2C100&tertiaryColor=F2F2F2%2C100&accentColor=33B5E5%2C100&cabBackColor=FFFFFF%2C100&cabHighlightColor=33B5E5%2C100
You can implement by create a custom tab indicator view and use setIndicator to implement different different indicator for tabs.
The one and the best way to change selector color is to use Styles (I saw "Please Note", btw).
In drawable folder create tab_selector.xml and do something like this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="#drawable/tab_selected_pink" />
<item android:state_selected="false" android:drawable="#drawable/tab_unselected_white" />
</selector>
and then in your values/styles.xml I guess, do something like this:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarTabBarStyle">#style/MyTabStyle</item>
</style>
<style name="MyTabStyle" parent="android:Widget.ActionBar.TabBar">
<item name="android:background">#drawable/tab_indicator_selector</item>
</style>
I'm possibly wrong with item name attribute in first style and parent attribute in second style. But in common it's will look like this.
As you can see it is easy to do.
All that you really have to do is make 9patch drawables, if you want to support different screens.
Also you can look at Jake Wharton's ViewPagerIndicator that's is most flexible way to use any Navigation Mode.
You'll want to chain
setIcon(R.drawable.ic_icon_name_here)
for your tabs to have icons
For the tab colors you'll want to use a custom style, for more info on those solutions take a look at How do I change the background of an Android tab widget?
If you know how many tabs you will have it is quite easy to change the icon color programmatically for each one or only a few of them.
All you need to do is copy your existing drawable file which is used for your tab, give it a name and then change the color within it.
Then all you need to do is get each tab and set the drawable you wish to use as the icon.
tabLayout.setupWithViewPager(pager, true);
tabLayout.getTabAt(0).setIcon(R.drawable.tab_color_grey);
tabLayout.getTabAt(1).setIcon(R.drawable.tab_color_black);
tabLayout.getTabAt(2).setIcon(R.drawable.tab_color_black);
tabLayout.getTabAt(3).setIcon(R.drawable.tab_color_black);
tabLayout.getTabAt(4).setIcon(R.drawable.tab_color_gold);
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.
In my application I have different Themes - one dark and one bright theme. Each theme requires his own icon set.
How do I apply it to the theme? Is there something like a special folder like for icons with different sizes ?
The following serves as a hint...
I suppose this may help: http://developer.android.com/reference/android/R.attr.html#icon
Lets say you have the following themes...
<style name="MyTheme.Dark">
...
</style>
<style name="MyTheme.Light">
...
</style>
You can add <item name="android:icon"></item> to each theme and supply each one with their own drawable icon. Then to get the respective drawables in your layout or what have you, you need to make use of ?android:attr/icon.
So your layout may end up looking something like...
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:attr/icon"/>
If you're unsure about what the ?android:attr/icon part exactly means, read http://developer.android.com/guide/topics/resources/accessing-resources.html#ReferencesToThemeAttributes.
Is there something like a special folder like for icons with different sizes ? (up to my knowledge) NO
no such default folder exist which you can use for Themes.
You need to do it programmatically.
Save the theme info in your Shared Preferences.
and at time of loading the view you can set your desired themed drawable.
I have been working with the ActionBar and ActionBarSherlock for the last few days, and i am having some issues when filling some information in the ActionBar.
When the application runs in portrait mode, the ActionBar looks fine, and all the data can be displayed, for example:
But when i switch the app to be displayed in landscape, some of the data is cropped:
You can notice how both the status icon and the email has been cropped due to the new height of the ActionBar.
In this case, i want to keep the same size for portrait and landscape so the app can look fine. I can't reduce the font size of the action bar title, since it may include other icons.
The way i´m putting these icons in the action bar title and subtitle is by using Html.fromHtml
Any ideas to solve this problem? I am using the ActionBarSherlock library!
One, probably not too pretty approach, could be to override the default height values for the ActionBar in dimens.xml.
E.g. the default value in portrait is:
<dimen name="abs__action_bar_default_height">48dip</dimen>
And in landscape:
<dimen name="abs__action_bar_default_height">40dip</dimen>
There might be a cleaner way to do it, but I have to admit I know too little about the internals of ActionBarSherlock for that.
Edit: Come to think of it, this probably won't work when the native ActionBar is being used on ICS, since the height will then resolve to the platform value in ?android:attr/actionBarSize. I'd recommend you wait for a better suggestion, e.g. from Jake himself.
Second edit:
After Jake's reply it seems like all you need to do to make it work with ActionBarSherlock on both ICS and pre-ICS devices is add the following to your app's theme:
<item name="actionBarSize">#dimen/some_value</item>
<item name="android:actionBarSize">#dimen/some_value</item>
You can then add the actual values in the relevant portrait/land resource buckets.
Third edit [thanks alvarolb]: XML Example for the style:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Styled" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarSize">48dip</item>
<item name="android:actionBarSize">48dip</item>
</style>
</resources>
And in the corresponding activity, set this new style
android:theme="#style/Theme.Styled"
and.. it works!