According to Material documents you could use "PrimarySurface" styles for components like toolbar and tab layout to switch their background color between color Primary and Surface in light mode and dark mode for android 10 and higher. This is my styles xml file.
<style name="AppTheme" parent="LightCustomFontStyle">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryVariant">#color/colorPrimaryDark</item>
<item name="colorSecondary">#color/colorAccent</item>
<item name="toolbarStyle">#style/toolbarStyle</item>
</style>
<style name="toolbarStyle" parent="Widget.MaterialComponents.Toolbar.PrimarySurface"/>
And dark mode elevation is supposed to be displayed with lighter colors but the thing is that colorSurface and colorBackground have the same value(#121212) and so in dark mode if you use these two at the same time, your toolbar won't display any elevation in relation to your activity.
It will look like this but I need it to look like the toolbar in Material docs. Also setting elevation for the toolbar doesn't work.
Is there anyway to get the elevated toolbar(lighter color) with Material and google styles or I should just set the lighter colors manually?
You can check the doc:
in a dark theme the elevation overlays are semi-transparent white (colorOnSurface) overlays that are conceptually placed on top of the surface color.
The overlay is based on the colorOnSurface defined in the app theme.
You can change this color adding in the app theme:
<item name="elevationOverlayColor">#color/...</item>
Related
In MaterialComponents theming we can use attributes to either use the default styles or extend them to reflect your design guidelines, e.g.:
<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">
...
<item name="textAppearanceCaption">#style/TextCaption</item>
...
</style>
<style name="TextCaption" parent="TextAppearance.MaterialComponents.Caption">
<item name="fontFamily">#font/inter_regular</item>
</style>
Then the framework automatically applies opacity to the text colors based on the theme, which is kinda cool, because you don't need to handle it manually. For example as far as I know the normal texts in light theme are getting 87%, the caption is getting somewhere around 40%.
But what if I'd like e.g. make the textAppearanceCaption have the same opacity as body1 app-wide without setting the color directly? Is something like this possible? How and when is this opacity applied by the framework? Is it the part of styles?
In my app you can change the theme from Light to Dark and vice versa. What this is doing setting the theme to either Theme.AppCompat.Light.DarkActionBar or Theme.AppCompat and finishing and starting the activity for the layout to load again.
I want to be able to change the color of those three purple lines dividing the settings to the same color of another view in the layout (for example the text). When I switch to dark theme, I want the lines color to change to the exact same color of the text and vice versa for when I switch to light theme. Light theme => dark lines, Dark theme => light lines. I need to be able to do this programatically to whatever the text color is because it is a different shade in different API levels. This is why setting the colors to hard coded values won't work.
You could redefine the dark and light themes for the android:divider item by adding the following line to both the theme styles.
<item name="android:divider">your_color</item>
An example of dark theme style would be:
<style name="MyDesign" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimaryDark">yourcolor</item>
<item name="colorPrimary">yourcolor</item>
<item name="colorAccent">yourcolor</item>
<item name="android:textColorPrimary">#color/textColorPrimary</item>
<item name="android:textColorSecondary">#color/textColorSecondary</item>
<item name="android:divider">yourcolor</item>
<item name="android:windowBackground">#color/window_background</item>
</style>
So my app theme extends from AppCompat's Material Light theme with Dark Action Bar.
I applied an accent color.
Now I am trying to use a Spinner on a dark backround and because of the theme, the spinner has a dark gray arrow which changes to accent color when pressed.
How can I make this spinner's arrow white so that it is prominent on a dark background?
Here's the image of the Spinner:
If you want to apply same spinner style app wide, then in your values/styles.xml, override spinnerStyle with your custom style, which derives from an appcompat type and override android:background:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:spinnerStyle">#style/AppSpinner</item>
</style>
<style name="AppSpinner" parent="Widget.AppCompat.Spinner">
<item name="android:background">#drawable/your_spinner_background</item>
</style>
If you need a quick way to generate a spinner background, try android-holo-colors, choose Colored Spinner and supply your accent color.
So the support library 22.1 enables use of android:theme attribute on views. That should help here.
with android:background you can specify your own background resource. I find the arrow rather useless (tapping the spinner brings dropdown menu even without arrow) so if you don't want to draw a custom arrow image, just leave the background black or transparent.
In the app that I am making I want to theme some of my display widgets (dialog, actionbar, etc) but keep Theme.Holo as a parent for things I don't want to theme (buttons, spinners, etc)
So in my manifest I changed:
android:theme="#android:style/Theme.Holo"
to
android:theme="#style/CustomTheme"
and then in themes.xml I made my CustomTheme and overrode my actionbar and dialog:
<!-- Custom Holo (Dark) Theme -->
<style name="CustomTheme" parent="#android:style/Theme.Holo">
<item name="android:actionBarStyle">#style/CarCastActionBar</item>
<item name="android:alertDialogTheme">#style/CustomDialogTheme</item>
<item name="android:dialogTheme">#style/CustomDialogTheme</item>
<item name="android:alertDialogStyle">#style/CustomDialogTheme</item>
</style>
only now my spinners have gone back to an ugly white instead of the flat transparent look.
Why is it doing this? I can attach pictures if it would help
The default Holo theme, which you are using expects a dark background. So the ui elements will have a white translucent color. Trying using the Holo Light theme to have darker ui elements.
android:Theme.Holo.Light
I am working on an app which will be full-screen, but will utilize some of the functionalities of the ActionBar. With the Ice Cream Sandwhich release, I see that I get a blue line divider/separator as part of the ActionBar. Normally, it would be good for consistency, but in my case I need to remove the divider.
How can I remove or style the divider of the ActionBar in ICS?
Tried setting a custom theme with "android:style/Widget.Holo.ActionBar" as parent.
However, settings such as the one below has no effect
<item name="android:divider">#FFFFFF</item>
The graphic asset containing the blue bottom line is the background of the action bar's container view and is set to #android:drawable/ab_transparent_dark_holo when using the default Holo Dark theme.
To remove this line, you'll need to create a custom style for your action bar (based on Widget.Holo.ActionBar or Widget.Holo.Light.ActionBar (or the .Solid variants) and set the android:background to something that doesn't include the bottom border:
<style name="MyTheme" parent="android:Theme.Holo">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="android:Widget.Holo.ActionBar">
<item name="android:background">#drawable/your_background_here</item>
</style>
Note: Holo Dark/Light action bars have solid and transparent styles; this blue line appears by default for the transparent style. Holo Dark action bars are transparent by default and Holo Light action bars are solid by default.
Here is a simple way to remove the divider, works from API 07 using the actionbarcompat from the support library:
#Override
public void onCreate(Bundle savedInstanceState) {
//...
getSupportActionBar().setBackgroundDrawable(
getResources().getDrawable(R.drawable.whatever_you_want));
//...
}
Changing the activity theme to Theme.Holo.Light.DarkActionBar removes the blue line.
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:windowBackground">#android:color/black</item>
<item name="android:textColor">#android:color/white</item>
</style>
If you still want a black background you may want to change android:windowBackground and/or android:textColor
add this <item name="android:windowContentOverlay">#null</item> to your app theme.