Change Theme.AppCompat global color - android

I am using Theme.AppCompat.Light.NoActionBar for my activities. In standard this theme sets one color (green/blue hue) for all button text, dialog titles and stripes, check boxes, etc. I just need to change this base color to another. How can i do it?
For now I can only change accent color with:
<item name="colorAccent">#color/actis_app_green_accent</item>

You can use Theme.AppCompat.NoActionBar (for dark theme) and Theme.AppCompat.Light.NoActionBar (for light theme).
It will change the backgrounds and text color of some basic Views.
To to change specific view's colors you should add specific items inside theme block.
e.g.
<item name="colorButtonNormal">#color/color_primary</item>
<item name="colorPrimary">#color/color_primary</item>
<item name="colorPrimaryDark">#color/color_primary_dark</item>
<item name="colorAccent">#color/color_accent</item>

Related

The night/theme.xml in android studio

The "colorprimary" changes in themes.xml then the button colour also changes "(image in lite mode)enter image description here (image in dark mode)enter image description hereedittext hint selection colour also changes . I want to edit text colour with out changing the theme and without changing button colour
I think, is important to mention first that a theme is different than a style. Basically, when you apply a style it only affects to the component( edit text, view, textview, etc). But when you apply a theme it affects in general terms to the app. More info about in this Link.
So, if you are applying a theme probably you are modifying some attributes that are being used in the app scope such as primaryColor, secondaryColor, etc. Probably, the editText is using primaryColor in order to set the color of the hint and when you change to another theme, primaryColor is affected, then the color hint of the editText is affected as well.
Based on the above description, we can apply multiple solutions. I would like to suggest the following.
default theme.xml
<style name="AppTheme" parent="AppTheme.Base" />
<style name="AppTheme.Base" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="colorPrimary">#color/gray_medium_dark</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorPrimaryVariant">#color/gray_dark</item>
<item name="colorSecondary">#color/cyan</item>
<item name="editTextStyle">#style/CustomEditTextStyle</item>
</style>
nigh theme theme.xml
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:windowLightNavigationBar" tools:ignore="NewApi">false</item>
</style>
style.xml
<style name="CustomEditTextStyle" parent="Widget.AppCompat.EditText">
<item name="android:textSize">#dimen/text_size_16sp</item>
<item name="android:textColorHint">#color/gray_normal_light</item>
<item name="android:fontFamily">#font/roboto_condensed</item>
<item name="android:textColor">#color/colorPrimaryText</item>
<item name="android:inputType">textVisiblePassword</item>
</style>
Explanation: Another important point about style and themes is that we can apply something similar to inheritance. It means that we ca re-use some attributes or/and modify others.
So, <item name="editTextStyle">#style/CustomEditTextStyle</item> means that for all the edittext on my application I want to set up CustomEditTextStyle style. Also, in nigh theme we are applying parent as parent="AppTheme.Base" and this parent also has CustomEditTextStyle as style for edittext, so it will no change.

Android how to set color of a view to that of another view programmatically at runtime?

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>

Change summary text color of dialogpreference with preference V7

How can we change the text color of summary of preference. right now, its taking textcolorsecondary by default which is white color. but i dont want to use it. i want to use other color. because i need textcolorsecondary for overflow and back icon color.
you can see below image where summary text not showing because of white color.
i just face this issue and now i find perfect solution for your problem.
here i am going to color overflow menu using styles. if you want to color preference summary text then use below code.
<item name="android:textColorSecondary">#android:color/white</item>
the solution is quite easy. you just need to create one style(custom style) and use this styles in anywhere you want to use to show overflow menu icon (vertical three dots)color.
here is my custom style code (styles.xml) file :
<style name="OverflowStyle" parent="Widget.AppCompat.ActionButton.Overflow">
<item name="android:tint">#ffffff</item>
</style>
and now use this style anywhere. right now i use in my main theme(which is appTheme)
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="actionOverflowButtonStyle">#style/OverflowStyle</item>
</style>
and for summary text of preference screen just do nothing if you want default color.
and if you want custom color then use following style attribute in your theme
<item name="android:textColorSecondary">#android:color/white</item>
and that's it .
this will give below two results.

Change ActionBarCompat title color but not other texts color

I'm using last release of support library (V21) which include material themes (under Theme.AppCompat name) and I want to put ActionBar title in white. I tried to achieve it by using textColorPrimary (as it's shown there) attribut in my custom theme
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light">
<item name="colorPrimary">#color/orange</item>
<item name="colorPrimaryDark">#color/orange_dark</item>
<item name="colorAccent">#color/white</item>
<!-- This attribut set text color -->
<item name="android:textColorPrimary">#color/white</item>
</style>
With this I got a white actionbar title but all other text (textview, edittext) were white too...
Is there a way to change only actionbar title color with recently released features or the only way is to use a custom style for action bar, just like it was the case with Holo ?
Use #style/Theme.AppCompat.Light.DarkActionBar to invert the text color only in the Action Bar.

Custom Theme Android

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

Categories

Resources