Mixing holo light and holo dark EditText in theme - android

I am using Holo dark as the theme of my app. However, there is part of it where I wish to use the EditText from holo light as the background is light in this part. I have tried doing it in themes. It worked when I did something similar for a button (we wanted to use the gingerbread style button):
<style
name="Theme.Banks" parent="Theme.Sherlock.ForceOverflow">
<item name="android:buttonStyle">#android:style/Widget.Button</item>
</style>
I tried doing the same with android:editTextStyle, but it does not affect the drawable. That is handled by the attribute android:editTextBackground. Looking into the code, I cannot just override this and point it at the light theme because it references a private drawable:
This is from themes.xml in the SDK:
<item name="editTextBackground">#android:drawable/edit_text_holo_dark</item>
So my question is how to do this?
Another use case might be wishing to use the EditText from gingerbread.
Any ideas?

You could grab the drawables that you need out of the the sdk res folder and include them with your own project then reference your own copy of the holo light drawables for that one EditText.
Seems inefficient, but I am not sure of any other way to get around your style issue.

Related

Background Recyclerview shows incorrectly after changing to Light/ Dark theme from Android App

Anyone can help me?
I'm developing the Light and Dark theme function in the android app, everything goes fine, but the background of Recyclerview shows incorrectly.
The root background of xml file is White color and I didn't set background for recyclerview in xml. However, after changing from Light to Dark or Dark to Right=> background of recyclerview automatically change to a strange color(this color didn't see in my color.xml resource). I tried to set background of Recyclerview to #null or transparent in code and xml file as well but the background of recyclerview didn't remove that strange color.
So anyone knows exactly the reason why, please help me and much appreciated. Thanks
enter image description hereenter image description here
I am guessing you are using the DayNight Theme. If so you should have to themes.xml folder in res, one is called as mentioned and the other is with the extension (night). There you can define a color in both xml files. It has the same name but different color values like this:
<style name="AppTheme" parent="Theme.AppCompat.DayNight">
<item name="colorPrimaryDark">#ffffff</item> <!-- you normally shouldn't hardcode color -->
</style>
The same for your folder (night):
<style name="AppTheme" parent="Theme.AppCompat.DayNight">
<item name="colorPrimaryDark">#000000</item> <!-- you normally shouldn't hardcode color -->
</style>
The idea is to have one attribute name that contains 2 colors and takes the correct one if needed. For futher understanding I suggest to take a look at this reference to get more familiar with Themes and Styles. Now you set up your Day and Night files properly, you can implement it by using it in your recyclerView as follows:
android:background="?attr/colorPrimaryDark"
Another tip is to make custom colors in multiple colors.xml files to make them for more unique use. In this case colorPrimaryDark effect your whole app. It is also suggested to modify layouts and the visuals of widgets to take effect only on those. (e.x. your recyclerView). In my app I used colorPrimaryDark for all Background (that should be same for more clean design). I think you get the keypoint. Take a look around the net and this forum and you will find your final design strategy. Cheers! :)

How come the color I set for cardBackgroundColor isn't exactly the one that gets shown?

Background
I'm trying to prepare dark theme for an app, and one of the requirements is to have a specific color for cards and dialogs : #ff3c454c
The problem
Whether I set it by force ( app:cardBackgroundColor="#3c454c") , by reference ( app:cardBackgroundColor="#color/...) or just in the theme - in all cases I don't get the color I've set. Instead I get the color of #525A61.
I've tested just a red color (#f00) just to be sure it affects the card, and it does, and for this color it indeed gets to be fine. But for the color I've set, it doesn't.
What I've tried
As I wrote, I tried multiple ways to set the color. In the beginning I wanted to use just the theme itself, so I've set it as such:
styles.xml
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
...
<item name="colorBackgroundFloating">#color/colorBackgroundFloating</item>
<item name="colorSurface">#color/colorBackgroundFloating</item>
</style>
res/values-night/colors.xml
<color name="colorBackgroundFloating">#ff3c454c</color>
Later I tried to use the color directly and even set it as hard coded. Still got the incorrect color when it gets shown.
Seeing this could be a bug on the library itself, I've reported about this here (include a sample project, if you wish to check it out).
I've noticed the exact same issue occurs for BottomNavigationView and probably other similar cases.
The question
Why does it occur?
Is there any workaround for this?
Something that will fix it globally for all views that use these attributes ?
What you are seeing is the elevation overlay that they introduced to make elevation more noticeable while in Dark Theme, where shadows are not so visible. You can read about it here : https://material.io/develop/android/theming/dark/ in the section "Elevation Overlays"
The simple solution if you don't want this behavior is to add this to your theme.
<item name="elevationOverlayEnabled">false</item>
And you can also adjust it to another color or even a more subtle version of the overlay by changing the alpha:
<item name="elevationOverlayColor">#80FFFFFF</item>
EDIT with more info from https://github.com/material-components/material-components-android/issues/1133
If you want to disable it for only one component or widget, you can define a style for it with a theme overlay and use it in a specific layout:
<style name="ThemeOverlay.MyApp.ElevationOverlayDisabled" parent="">
<item name="elevationOverlayEnabled">false</item>
</style>
<style name="Widget.MyApp.CardView" parent="Widget.MaterialComponents.CardView">
<item name="materialThemeOverlay">#style/ThemeOverlay.MyApp.ElevationOverlayDisabled</item>
</style>
And if you want to disable it for all cards in your app but keep it in other components you can set that style as the default style for material card views:
# Set in your app theme
<item name="materialCardViewStyle">#style/Widget.MyApp.CardView</item>

Android custom button style: APi - < 21 and > 21 - attributes

I want to create several button styles instyles.xml. I want to support API 19 and higher so I would like to create button styles for both API. What I am doing:
I've created custom style in stylex.xml:
<style name="AppTheme.ButtonGreen" parent="android:Widget.Holo.Button">
<iten name="android:textColor">#color/accent</iten>
<item name="android:background">#color/primary</item>
</style>
In facy the color does not change. Can you help me with theming and give some basic attributes like: background color, text color etc. cause those does not work (only font color works).
I have also implemented style for v21 in styles (v21).xml:
<style name="AppTheme.ButtonGreen" parent="android:Widget.Material.Button">
<item name="android:textColor">#color/primary</item>
<item name="android:background">#color/text_icons</item>
</style>
But here I need font color, background color, elevation, font size etc. (only font color works).
Generally I guess I am doing something wrong. Can you guys help me style those buttons for different API?
Please read this article
https://www.androidcookbook.com/Recipe.seam?recipeId=3307
and this issue on StackOverflow:
How to create custom button in Android using XML Styles
I think the first one would be enough for your actual needs.
If you have question, please feel free to ask.
EDIT: if you still feel stuck - maybe it would be good to create an image and set it as ImageButton.
http://angrytools.com/android/button/
http://dabuttonfactory.com/
Or try to find issues abot using Material Design in lower APIs. This might be helpful: how to use material design features in api lower than 21 in eclipse?
you have to use background instead of backgroundtint

ActionBar Light, but Holo Dark ActionMode CloseButton

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.

Designing Android Themes

Can anyone tell me how I can change my apps theme from the default ones made available? Holo and Holo.Light get a bit boring after a while.
The likes of Facebook, Google+, BBC Weather, Viber, Vine and Twitter all look very professional and have their own theme whereas the app I'm developing looks quite boring.
Is it possible to change the font of the text in my app? I know it's possible to change the colour and size of it.
Another thing which would be useful to know would be how to change the colour of the action bar that is used for my app. Currently it's black but I wouldn't mind changing it to a different colour than those used by the Android default themes (e.g. purple, green, blue, etc)
Maybe you can share some tips on what you think works well for Android design?
You can generate a custom theme at http://jgilfelt.github.io/android-actionbarstylegenerator/
If you only want to change a few font an colors etc take a closer look at this (source:http://developer.android.com/guide/topics/ui/themes.html)
If you like a theme, but want to tweak it, just add the theme as the parent of your custom theme. For example, you can modify the traditional light theme to use your own color like this:
<color name="custom_theme_color">#b0b0ff</color>
<style name="CustomTheme" parent="android:Theme.Light">
<item name="android:windowBackground">#color/custom_theme_color</item>
<item name="android:colorBackground">#color/custom_theme_color</item>
</style>
(Note that the color needs to supplied as a separate resource here because the android:windowBackground attribute only supports a reference to another resource; unlike android:colorBackground, it can not be given a color literal.)
Now use CustomTheme instead of Theme.Light inside the Android Manifest:
<activity android:theme="#style/CustomTheme">

Categories

Resources