I know it's possible to replace the icon by setting a custom actionOverflowButtonStyle as described here. However, that style only allows setting a different drawable and or/background.
Instead, I would like to use the standard icon provided by AppCompat, just tinting it with a particular color, just as the drawer icon/back button can be tinted via the color attribute in drawerArrowStyle.
I have tried these methods, which reportedly used to work:
Setting colorControlNormal -- Toolbar icon tinting on Android
Setting textColorPrimary in the theme -- MenuItem tinting on AppCompat Toolbar
Setting a custom actionBarStyle and changing colorControlNormal there.
But as far as I can see none of them work with the latest AppCompat -- the overflow icon keeps its original color (while other widgets, such as TextViews or the text in menu items do change).
Should this be done differently now? I am not using a custom Toolbar view, just the default AppCompat-provided, ActionBar-like one.
How to reproduce:
Create a default Android Studio project, with minimum SDK version = 9.
This automatically includes a blank activity and a menu resource with a single menu item, "Settings", with app:showAsAction="never" which means it will be displayed in the overflow menu.
Finally, customize the styles.xml file. For example:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#008888</item>
<item name="colorControlNormal">#ff0000</item>
<item name="android:textColorPrimary">#ff0000</item>
</style>
</resources>
You'll notice that neither property affects the overflow menu icon color. Tested in a Nexus 5 with Android 5.1.1.
If you trace the Theme.AppCompat.Light.DarkActionBar theme, you see that it sets:
<item name="actionBarTheme">#style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
Which in turn inherits from Base.ThemeOverlay.AppCompat.Dark, which sets:
<item name="android:textColorPrimary">#color/abc_primary_text_material_dark</item>
Which essentially equals white:
<color name="primary_text_default_material_dark">#ffffffff</color>
If you just inherit from Base.Theme.AppCompat.Light, you won't run into this issue since it doesn't set the actionBarTheme. You can easily customize the action bar using the material properties anyway.
Related
My problem is easy but I need some help
I have a MainActivity, several Fragments and NavigationDrawer. I also use a Appcompat v7
NavigationDrawer is shown behind the statusbar for what I use ScrimInsetsLayout.
In styles I have colorPrimary and colorPrimaryDark(parent is Theme.Appcompat)
In main activity I use setStatusBarColor(Color.TRANSPARENT) to show Drawer in statusbar. So now I have colorPrimaryDark statusbar color and NavigationDrawer in statusbar
Now I created a new Fragment and I need to disable colorPrimaryDark color and make statusbar real transparent
As I said before, setting color to transparent makes it colorPrimaryDark with drawer shown
Setting it to any other color "hides" drawer.
Thanks
Screenshots:
The transparent translucent status bar is available from API 19, create a new values-v19 folder and a styles.xml inside it then update your BaseAppTheme like this:
<!-- Base application theme for v19. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
But, this would make your UI use the space behind StatusBar, so I would suggest adding an extra TOP padding, of 25dp (researched and found every API uses 25dp as StatusBar height even in landscape mode), for devices > API19
I had my app looking pretty nice using the new Lollipop tools. I decided backwards compatibility is important, so I switched all my Fragments,actionBar imports to the support library. Now (understandably) I can't use my lollipop theme.
Is there a way to use different action bars for different themes? I tried to cast the support ActionBar to a new one but it doesn't seem this is allowed.
My problem lies with the following (from v21 docs)
All of your Activities must extend from ActionBarActivity, which
extends from FragmentActivity from the v4 support library, so you can
continue to use fragments. All of your themes (that want an Action
Bar/Toolbar) must inherit from Theme.AppCompat. There are variants
available, including Light and NoActionBar. When inflating anything to
be displayed on the action bar (such as a SpinnerAdapter for list
navigation in the toolbar), make sure you use the action bar’s themed
context, retrieved via getSupportActionBar().getThemedContext(). You
must use the static methods in MenuItemCompat for any action-related
calls on a MenuItem.
so by calling getsupportActionBar I can't use my Holo theme:
<resources>
<!-- Base application theme. -->
<style name="appTheme" parent="android:Theme.Holo.Light.DarkActionBar">
</style>
<style name="MyActionBar"
parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:background">#color/blue_semi_transparent</item>
</style>
</resources>
Also for some reason the action bar loses the button that was on it and it goes into the dropdown menu and the app icon no longer appears in the action bar.
I really am no expert on this stuff having only started developing on lollipop so would really appreciate advice.
AppCompat (i.e., ActionBarActivity) uses the Material color palette which defines default coloring throughout your app. In your case, you need to use colorPrimary for your action bar color:
<style name="appTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/blue_semi_transparent</item>
</style>
Note that you should also provide a colorPrimaryDark (a darker version of the same color) for coloring the status bar.
Per the partially outdated Action Bar training, AppCompat also uses app namespaced attributes (as things like showAsAction didn't exist before API 11) for your menu items:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
app:showAsAction="ifRoom" />
...
</menu>
Per the Toolbar documentation (which is default behavior on Material themes and in AppCompat):
In modern Android UIs developers should lean more on a visually distinct color scheme for toolbars than on their application icon. The use of application icon plus title as a standard layout is discouraged on API 21 devices and newer.
Therefore as you noted the app icon not appearing on the Action Bar is expected behavior.
I have a Theme.Holo.Light style, which is custom designed. Therefore I want to have the little tick on the contextual action mode in normal Theme.Holo style.
As you can see, it would look much better if the tick was white.
I thought the following would work, but no success.
<style name="PlayerTheme" parent="#android:style/Theme.Holo.Light">
...
<item name="android:actionModeCloseButtonStyle">#android:style/Widget.ActionButton.CloseMode</item>
</style>
Is there some way to make the tick white? Thanks!
You can copy the standard white check mark from the android icon pack into your project as a drawable. The icon pack can be found here: https://developer.android.com/design/downloads/index.html. It's under the 01_core_accept folder and named ic_action_accept.png.
Then, set the following property in your style file:
<item name="android:actionModeCloseDrawable">#drawable/ic_action_accept</item>
That should solve your problem.
I have used Android Support V7's #style/Theme.AppCompat.Light for my styles. And to be more specific I have used Actionbar Style Generator
I want my overall theme to be in light red. So,for options menu item selector,I need light red color to work. I have made Accent color in Actionbar Style Generator to red as well. But the options menu item is always default blue. I have changed following as well to be sure
<item name="popupMenuStyle">#style/PopupMenu.Fsa</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Fsa</item>
<style name="DropDownListView.Fsa" parent="#style/Widget.AppCompat.Light.ListView.DropDown">
<item name="android:listSelector">#drawable/red_selector</item>
</style>
But also,the options menu item selector is always default blue. I have browsed several tutorials on Actionbar styling and they were also of no help. So any help would be greatly appreciated.
Depending on your hardware needs Android Support or not, your XML must contain both item style reference:
<!-- Support library compatibility -->
<item name="popupMenuStyle">#style/PopupMenu.Fsa</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Fsa</item>
and
<!-- Support library not needed -->
<item name="android:popupMenuStyle">#style/PopupMenu.Fsa</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.Fsa</item>
regardless the fact of Android Studio show error for "requires API level XX", it compiles as well and now the correct styles are applicable in both hardware, who needs and not the support library.
In my AndroidManifest file i do not declare a theme.
The result is:
black background and ABS with blue background, also states of list item's is blue.
thats fine.
now i want to make to set the indeterminateProgressStyle to Widget.ProgressBar.Small
Therefore i have to declare my own style like this:
<style name="Custom" parent="??">
<item name="android:actionBarStyle">#style/ActionBarIPS</item>
</style>
what should i enter in the parent parameter?
i want all style behaviors like before (black background with blue ABS and blue list item states etc as it is defined when i dont declare a theme attribute in AndroidManifest.
EDIT:
i also need to know this parent's value:
<style name="ActionBarIPS" parent="ABS with blue background">
<item name="android:indeterminateProgressStyle">#style/IndeterminateProgress</item>
</style>
the version without a style in manifest:
the version with custom style and parent=Theme.Sherlock
i want the first version with indeterminate spinner set to "small"
It's depend to your current style, It can be Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.ForceOverflow and etc, e.g:
<style name="Custom" parent="Theme.Sherlock or Theme.Sherlock.Light">
<item name="android:actionBarStyle">#style/ActionBarIPS</item>
<item name="android:indeterminateProgressStyle">#style/IndeterminateProgress</item>
</style>
Note: You must declare this style in style.xml in your values directory.
Edited:
You got blue ActionBar without using ABS because you're using Samsung TouchWiz default UI.
If you install your APK in non-samsung devices you won't see this blue action bar, But If you are forced to have blue actionbar then put the following image in your drawable directory and set it as your actionbar background through:
getSupportActionBar().setBackgroundDrawable(getResources()
.getDrawable(R.drawable.TouchWiz_ActionBar_Bg));
Try to use "Theme.Sherlock" as a parent. Also I suggest to add:
<item name="actionBarStyle">#style/ActionBarIPS</item>