I am using custom title bar and its shows content as Theme.light. I tried to change it Theme.Holo but it doesn't work. can anyone help me?
<resources>
<style name="CustomWindowTitleBackground" >
<item name="android:background">#DDDDDD</item>
</style>
<style name="CustomTheme" parent="android:Theme.Holo">
<item name="android:windowTitleSize">73dip</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowTitleBackgroundStyle">#style/CustomWindowTitleBackground</item>
</style>
Provide some more details. Are you using the support action bar? When using the app compat action bar (from the support library) you can only use Theme.AppCompat / Theme.AppCompat.Light and related ones for your activity.
Related
I am new to Android themes, so this is probably a beginners question but I just can't figure it out.
<style name="MyAppTheme" parent="android:Theme.Material">
<item name="android:colorPrimary">#color/primary</item>
<item name="android:colorPrimaryDark">#color/primary_dark</item>
</style>
I want to use the new Material theme, so I used Theme.Material with my own colorPrimary and primaryDark colors to get the action bar the way I want it. But for the context menu (the one that opens when you press the 3-dots icon in the top right corner) I want to use the Theme.Material.Light version. So I want the context menu with black text on a white background instead of white text on a gray background.
How can I do this?
I would advise against using the "Material" theme. It's not supported on older devices. However if you use AppCompat then it will achieve the same effect but with backwards compatibility.
If you create a new Activity using the template it will work as you want. Nevertheless, this is the code:
<!--Application-->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="popupTheme">#style/NewAppTheme.PopupOverlay</item>
</style>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
Add this theme to your Toolbar:
app:popupTheme="#style/myStyle"
Define backgroundcolor and textColor in your custom theme for the pop-up menu:
<style name="myStyle" parent="ThemeOverlay.AppCompat.Light">
<item name="android:colorBackground">yourBackgroundColor</item>
<item name="android:textColor"yourTextcolor></item>
</style>
If you are using ActionBar then use ActionBar Generator and use the generated files in your res folder.
Hope this helps.
I am trying to style the overflow menu items on the action bar but so far I've had no luck. I am testing on Android API 21 but my minimum version is set to 17. I am using the theme DeviceDefault. I tried setting the theme to Holo but the action bar disappears completely then. Anyways, here are the styles I'm currently using for the action bar:
<style name="AppBaseTheme" parent="android:Theme.DeviceDefault">
<item name="android:popupMenuStyle">#style/PopupMenu</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="android:displayOptions">showHome|useLogo|showTitle</item>
</style>
<style name="AppTheme" parent="AppBaseTheme">
</style>
<style name="MyActionBar">
<item name="android:background">#drawable/gradient3</item>
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<style name="PopupMenu" parent="android:Widget.DeviceDefault.ListPopupWindow">
<item name="android:popupBackground">#drawable/gradient1</item>
<item name="android:textColor">#color/ed</item>
</style>
<style name="MyActionBarTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/ed</item>
<item name="android:textSize">18sp</item>
</style>
So far popupMenuStyle seems to be ignored on API 21 but the action bar background takes effect. What is the correct way of styling the overflow menu for android versions 17 onwards? Also, is it recommended to use DeviceDefault as the theme and if not, is there a reason the Holo theme is making the action bar disappear?
Thank you. I appreciate any help.
According to https://developer.android.com/training/material/theme.html , colorPrimary should set the action bar color.
This works when my mainActivity extends Activity, but it breaks when I extend instead AppCompatActivity (or the now-deprecated ActionBarActivity).
So for AppCompatActivity I must use:
values/style.xml
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimaryDark">#color/MaterialTeal800</item>
<item name="colorPrimary">#color/MaterialTeal500</item>
<!--<item name="colorPrimaryLight">#color/MaterialLightPrimary</item>-->
<!--<item name="colorDivider">#color/MaterialDivider</item>-->
<item name="colorAccent">#color/MaterialDeepOrange500</item>
<!--<item name="colorAccentPressed">#color/MaterialDeepOrange800</item>-->
</style>
<style name="AppTheme" parent="AppBaseTheme">
<!-- Customize your theme here. -->
<item name="android:textColor">#color/black</item>
<item name="android:textColorSecondary">#color/MaterialSecondary</item>
<item name="android:textColorPrimary">#color/black</item>
<item name="actionBarTabTextStyle">#style/TitleText</item>
</style>
<style name="TitleText" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:textColor">#color/white</item>
</style>
which colors the status bar correctly, but NOT the action bar.
And (for v21, anyway) for Activity it works with
<style name="AppBaseTheme" parent="android:Theme.Material.Light.DarkActionBar">
<!-- android:Theme.Material.Light.DarkActionBar -->
<!-- Theme.AppCompat.Light.DarkActionBar -->
<item name="android:colorPrimaryDark">#color/MaterialTeal800</item>
<item name="android:colorPrimary">#color/MaterialTeal500</item>
<!--<item name="android:colorPrimaryLight">#color/MaterialLightPrimary</item>-->
<item name="android:textColor">#color/black</item>
<item name="android:actionBarTabTextStyle">#style/TitleText</item>
<item name="android:textColorSecondary">#color/MaterialSecondary</item>
<!--<item name="android:colorDivider">#color/MaterialDivider</item>-->
<item name="android:textColorPrimary">#color/black</item>
<item name="android:colorAccent">#color/MaterialDeepOrange500</item>
</style>
If I don't use Activity and use AppCompatActivity instead, it crashes on launch, saying:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
I'd like to run with AppCompatActivity for, well, compatibility, but I can't figure out why it's not picking up the color (yet the same code works great with Activity -- and I'd love to use all the newer options on API 21+). It seems wrong that it'd pick up the status bar but I'd need to manually override a custom style on the action bar (a-la this answer). Am I stuck picking and choosing? No Material themes or transitions, or backward compatibility?
Note this is not a toolbar. This is the action bar -- I know I can use android:background on an added toolbar element.
Update
Looks like I can get the actionbar to color with AppCompatActivity by dropping the v21 android: namespace, but still get the crash if I try to use the real material theme ...
Here you should remove android: prefix for app compat theme like:
<item name="colorPrimaryDark">#color/MaterialTeal800</item>
and in styles-v21
<item name="android:colorPrimaryDark">#color/MaterialTeal800</item>
I'm trying to change the height of my action bar to give it a more Material feel, but whatever I try never seems to work. Currently I have this:
<!-- Main Theme -->
<style name="WPTheme" parent="Theme.Sherlock">
<item name="actionBarStyle">#style/WPTheme.ActionBarStyle</item>
<item name="android:actionBarStyle">#style/WPTheme.ActionBarStyle</item>
<item name="android:actionBarWidgetTheme">#style/CustomActionOverflowDropDownText</item>
<item name="actionBarWidgetTheme">#style/CustomActionOverflowDropDownText</item>
<item name="android:textColor">#android:color/white</item>
<item name="android:actionOverflowButtonStyle">#style/MyOverflowButton</item>
<item name="textColorPrimaryInverse">#android:color/white</item>
<item name="android:windowBackground">#drawable/black</item>
</style>
<!-- Action Bar Theme -->
<style name="WPTheme.ActionBarStyle" parent="Widget.Sherlock.ActionBar">
<item name="background">#drawable/ic_bar_top</item>
<item name="android:background">#drawable/ic_bar_top</item>
<item name="actionBarSize">56dip</item>
<item name="android:actionBarSize">56dip</item>
<item name="actionOverflowButtonStyle">#style/Widget.Sherlock.ActionButton.Overflow</item>
<item name="dropDownListViewStyle">#style/Widget.Sherlock.Light.ListView.DropDown</item>
</style>
Is there any other solutions out there? Or am I just making some bone-head error here that I'm not picking up on? Thanks!
Changing of height of actionbarsherlock is not the solution.
Use Translucent system bars
You can now make the system bars partially translucent with new themes,
Check this project https://github.com/jgilfelt/SystemBarTint
If you're creating a custom theme, set one of these themes as the parent theme or include the windowTranslucentNavigation and windowTranslucentStatus style properties in your theme.
Hope this helps get you started.
Move <item name="actionBarSize">56dip</item> and <item name="android:actionBarSize">56dip</item> to your main theme.
Also, if you'd like, you can check out my blog post on achieving a material style action bar on older android versions here. Though I haven't written it to be used with ActionBarSherlock, with some slight modifications, you should be able to get the same thing working.
I'm working with the new Lollipop Material Design guidelines and would like to incorporate that nifty navigation drawer animation in my app. I've gotten that far, by using the android.support.v7.app.ActionBarDrawerToggle, but now I'm having difficulty changing the color of said action bar. It stays bright gray no matter what I set the theme to. How would one go about changing the color of the actionbar? This is what my app theme looks like:
//res/values/styles.xml
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="android:colorPrimary">#color/primaryDef</item>
<item name="android:colorPrimaryDark">#color/primaryDarkDef</item>
<item name="android:activatedBackgroundIndicator">#drawable/defbg</item>
<item name="android:colorAccent">#color/primaryDef</item>
<item name="android:navigationBarColor">#color/primaryDarkDef</item>
</style>
<style name="ActionBar" parent="android:Widget.ActionBar">
<item name="android:background">#color/primaryDef</item>
</style>
AppCompat does not use the android: prefixed attributes for the Material Theme color palette items per the migration guide to v21 by the author of AppCompat. Instead, just use the names themselves:
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primaryDef</item>
<item name="colorPrimaryDark">#color/primaryDarkDef</item>
<item name="colorAccent">#color/primaryDef</item>
<item name="android:navigationBarColor">#color/primaryDarkDef</item>
<item name="android:activatedBackgroundIndicator">#drawable/defbg</item>
</style>
The Action Bar will be colored by colorPrimary.