I want to change the color of the arrow in the fab button from black to white, this is how it looks currently in the theme editor:
And this is my code in styles.xml:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar" >
<item name="colorAccent">#color/accent</item>
<item name="colorForeground">#color/primary</item>
<item name="colorPrimary">#color/primary</item>
<item name="navigationBarColor">#color/white</item>
<item name="statusBarColor">#color/primary_dark</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="android:navigationBarColor">#color/primary</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="titleTextStyle">#style/MyTitleTextStyle</item>
</style>
<style name="MyTitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
</style>
</resources>
I have already manage to change the text color in the App Bar thanks to other answers but I haven't found a way to change this other part.
I'm using appcompat-v7:25.2.0
You could specify any icon with any color for your fab, using src parameter:
Here is an example from our project:
<android.support.design.widget.FloatingActionButton
android:id="#+id/training_player"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:src="#drawable/play_fap"
app:layout_anchor="#id/appbar"
app:layout_anchorGravity="center_horizontal|bottom"
/>
Or you can simply add color tint to change color of existing icon:
android:tint="#color/white"
The following solution relies on support vectors. Read more here.
my_vector_drawable.xml
<vector
android:tint="?colorControlNormal">
...
</vector>
You can tint support vector drawables. ?colorControlNormal is an attribute defined by your theme. In light themes its semi-transparent black, in dark themes it's semi-transparent or opaque white.
layout.xml
<FloatingActionButton
style="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:srcCompat="#drawable/my_vector_drawable/>
Two things happen here:
Use app:srcCompat which will safely set a support vector drawable on all API levels.
Set a dark theme on the FAB. This will make the icon and the ripple effect white.
Theme explanation:
Dark theme = light foregrounds (text, icons, highlights), dark backgrounds.
Light theme = dark foregrounds, light backgrounds.
Related
I am changing color of MaterialTimePicker buttons text by changing colorPrimary of my time picker style. But when I change colorPrimary - chip in selected state also changes it's color.
What I want to achive is to make Ok and Cancel buttons text white, and selected chip leave Blue. On the screen my colorPrimary is Blue.
Is there a way to change buttons text color independently?
<style name="TimePicker" parent="#style/ThemeOverlay.MaterialComponents.TimePicker">
<item name="colorPrimary">#color/blue</item>
<item name="colorSurface">#color/dark_grey</item>
<item name="colorOnSurface">#color/light_grey</item>
<item name="colorOnPrimary">#color/white</item>
<item name="colorOnSecondary">#color/colorAccent</item>
<item name="chipStyle">#style/chipStyle</item>
<item name="materialClockStyle">#style/clockStyle</item>
<item name="imageButtonStyle">#style/Widget.MaterialComponents.TimePicker.ToggleButton</item>
</style>
<style name="chipStyle" parent="Widget.MaterialComponents.TimePicker.Display">
<item name="android:textColor">#color/selector_time_picker_chip_text_color</item>
</style>
I think i found a method.
From the source code we can see that these two buttons (OK and CANCEL) are using borderlessButtonStyle :
<Button
android:id="#+id/material_timepicker_cancel_button"
style="?attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginEnd="8dp"
android:minWidth="72dp"
android:text="#android:string/cancel"
app:layout_constraintEnd_toStartOf="#id/material_timepicker_ok_button"
app:layout_constraintTop_toTopOf="#id/material_timepicker_mode_button" />
So we can simply override the borderlessButtonStyle style in the TimePicker style to change the colors. Like this :
themes.xml :
<style name="ThemeOverlay.App.TimePicker" parent="ThemeOverlay.MaterialComponents.TimePicker">
<item name="borderlessButtonStyle">#style/borderlessButtonStyle</item>
</style>
<style name="borderlessButtonStyle" parent="Widget.MaterialComponents.Button.TextButton">
<item name="android:textColor">#color/white</item>
</style>
then in the end add this line in your main app's theme :
<style name="Theme.StackOverflow" parent="Theme.MaterialComponents.Light.NoActionBar">
...
<item name="materialTimePickerTheme">#style/ThemeOverlay.App.TimePicker</item>
...
</style>
This will work. Please feel free to improve my answer .
I am using the MaterialButtons where the colors change as per the background tint. I am changing the styles using setTheme(R.style.theme) in the app but the buttons do not change with the theme. More over if I define the background tint in the style the entire apps background is messed up.
example
<style name="AppThemeGreen" parent="AppTheme">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/green</item>
<item name="colorPrimaryDark">#color/green</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:backgroundTint">#color/green</item>
</style>
How do I set the tint color as per the theme I do not want to find the views and use checks progmatically. That would be too tedious how do I do it using styles.
you can create style like this in style.xml file
<style name="PrimaryButton" parent="Theme.AppCompat">
<item name="colorButtonNormal">#color/colorPrimary</item>
<item name="colorControlHighlight">#color/colorAccent</item>
</style>
and give it to button as below
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/click_me"
android:theme="#style/PrimaryButton" />
I am using MaterialComponents.DayNight theme in my app. In the day mode, toolbar text color is black. But when I switch to night mode toolbar text color is remain black, so it's not visible anymore.
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
I want to change the toolbar text color into white in night mode. How can I do that?
Just use in your Layout (it works also with the androidx.appcompat.widget.Toolbar) the style:
<com.google.android.material.appbar.MaterialToolbar
style="#style/Widget.MaterialComponents.Toolbar.Primary"
Then define in the values-night/colors.xml the colorOnPrimary.
Then there are a lot of alternatives.
You can customize globally the style of the toolbar in the app theme with:
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<item name="toolbarStyle">#style/MyToolbar</item>
</style>
with:
<style name="MyToolbar" parent="Widget.MaterialComponents.Toolbar.Primary">
<item name="titleTextColor">#color/.....</item>
</style>
and the define the color in the values/colors.xml and values-night/colors.xml.
Or just apply a style in the Toolbar
<com.google.android.material.appbar.MaterialToolbar
style="#style/MyToolbar"
or simply override the theme with:
<com.google.android.material.appbar.MaterialToolbar
android:theme="#style/MyThemeOverlay_Toolbar"
with:
<style name="MyThemeOverlay_Toolbar" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
<item name="colorOnPrimary">#color/...</item>
</style>
Set your parent theme to parent="Theme.MaterialComponents.DayNight.DarkActionBar.Bridge"
By using this, you will keep your ActionBar's original theme with DarkActionBar attributes on top of the overal DayNight theme from MaterialComponents.
Add this entry to your theme:
<item name="android:itemTextAppearance">#style/PopupMenuTextAppearance</item>
After that, add the style accordingly to the styles.xml:
<style name="PopupMenuTextAppearance" parent="TextAppearance.AppCompat.Menu">
<item name="android:textColor">?attr/colorOnBackground</item>
</style>
?attr/colorOnBackground is available in the Material Components library. If you're not using that, you should be able to use ?android:attr/textColorPrimary instead.
in my opinion you should set the style on noActionbar and design new toolbar and customize it
I used these two lines of code inside the styles.xml file:
<item name="colorControlNormal">#android:color/white</item>
<item name="android:textColorPrimary">#android:color/white</item>
It changed the color on the toolbar text and the toolbar X icon to white.
The whole code looked like this:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#00695c</item>
<item name="colorPrimaryVariant">#439889</item>
<item name="colorOnPrimary">#ffffff</item>
<item name="colorSecondary">#007769</item>
<item name="colorSecondaryVariant">#48a697</item>
<item name="colorOnSecondary">#ffffff</item>
<item name="colorControlNormal">#android:color/white</item>
<item name="android:textColorPrimary">#android:color/white</item>
</style>
</resources>
I'm trying to change ActionBar text color like this.
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="actionBarStyle">#style/MyTheme.ActionBarStyle</item>
</style>
<style name="MyTheme.ActionBarStyle" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
</style>
According to a lot of similar topics (another one) this should work, but none of that changes text color and also my ActionBar is becoming transparent when I try this. I can change it's text color by changing textColorPrimary in AppTheme, but it also changes a lot of stuff.
Also I'd like to see any links about how styling works in android cause it and it's hierarchy kinda confuses me
Why not you using ToolBar xml Like this
<android.support.v7.widget.Toolbar
android:id="#+id/videos_toolbar"
style="#style/ToolBarTextStyle"
android:layout_width="match_parent"
android:layout_height="?android:actionBarSize"
android:layout_alignParentTop="true"
android:background="#color/ToolBarColor"
android:paddingRight="#dimen/_32sdp"
android:textAlignment="center"
app:titleTextColor="#color/ThemeColor">
I saw that
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:textColorSecondary">#android:color/white</item>
affects both menu ... text color (as in ... icon on the right) but also change the border of an unchecked checkbox. What I've been trying to do is to give them different colors. I tried to give a different style to checkbox but no luck.
<style name="Checkbox" parent="Widget.AppCompat.CompoundButton.CheckBox">
<item name="android:textColorSecondary">#color/blue</item>
</style>
and
<CheckBox
android:id="#+id/activitySettings_checkBox_announce"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"
style="#style/Checkbox"/>
but seems impossible to give any style to the checkbox because it always use the activity's theme.
You can change color by using following attribute
<style name="CheckBox" parent="Widget.AppCompat.CompoundButton.CheckBox">
<item name="colorControlNormal">#color/checkbox_normal</item> <!-- border color -->
<item name="colorControlActivated">#color/checkbox_activated</item> <!-- fill color -->
<item name="colorControlHighlight">#color/checkbox_highlight</item> <!-- animation color -->
</style>