App Bar not following Headline 6 text appearance in dark theme (Material Design Components) - material-design

Project with MDC doesn't follow the fontFamily I set in Headline 6 in my theme when on dark theme.
I used metropolis_500 as my fontFamily in my Headline 6 style. It shows up normally on Light Theme but not on Dark Theme.
implementation 'com.google.android.material:material:1.1.0'
<!--Base Theme-->
<style name="Base.Theme.MyApp" parent="Base.Theme.MaterialThemeBuilder">
...
<item name="textAppearanceHeadline6">#style/TextAppearance.MyTheme.Headline6</item>
<item name="toolbarStyle">#style/Widget.MyTheme.Toolbar.AppBar</item>
...
</style>
<!--AppBar Style-->
<style name="Widget.MyTheme.Toolbar.AppBar" parent="Widget.MaterialComponents.Toolbar.Surface">
<item name="android:background">?attr/colorAppBar</item>
<item name="titleTextColor">?colorOnAppBar</item>
</style>
<!--Headline 6-->
<style name="TextAppearance.MyTheme.Headline6" parent="TextAppearance.MaterialComponents.Headline6">
<item name="fontFamily">#font/metropolis_500</item>
</style>
I tried explicitly specifying the use of Headline 6 in my AppBar Style and did not work.
<!--AppBar Style-->
<style name="Widget.MyTheme.Toolbar.AppBar" parent="Widget.MaterialComponents.Toolbar.Surface">
<item name="android:background">?attr/colorAppBar</item>
<item name="titleTextColor">?colorOnAppBar</item>
<item name="titleTextAppearance">#style/TextAppearance.MyTheme.Headline6</item>
</style>
I also tried explicitly specifying the toolbarStyle on Dark Theme Style.
<style name="Theme.MyApp" parent="Base.Theme.MyApp">
...
<item name="toolbarStyle">#style/Widget.MyTheme.Toolbar.AppBar</item>
</style>
I also tried reverting to the default Material Components toolbarStyle.
<item name="toolbarStyle">#style/Widget.MaterialComponents.Toolbar.Surface</item>
Nothing worked. Light theme is alright, but dark theme isn't. The metropolis font shows up properly on other parts in dark theme like in TextViews that use the Headline 6 style.

Related

MaterialButton style shapeAppearance not working

I'm struggling to set the right style for my button in the project. I don't know why shapeAppearance not working. Even if I use only cornerSize it's not working.
I have a base style for a button:
<style name="SnButton" parent="Widget.MaterialComponents.Button.UnelevatedButton">
<item name="shapeAppearance">#style/MyShapeAppearance</item>
<item name="backgroundTint">#null</item>
</style>
This is my shape appearance for a button:
<style name="MyShapeAppearance" parent="ShapeAppearance.MaterialComponents.SmallComponent">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">2dp</item>
</style>
This is my base theme: Theme.MaterialComponents.Light.NoActionBar.Bridge
What should I do to force shapeAppearance work in my case? Or at least cornerSize?
I figured out why style was not working!
The problem was in the way I set the color for the button. I've used android:background, but backgroundTint must be used.

Delete the night mode in my android application | android studio

I do not want the night mode in my application, I tried to delete a file themes.xml (night), But that didn't work, I also tried moving the themes.xml file content to a themes.xml (night) And it didn't work either.
themes.xml file
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Can you help me thanks!.
Please use default app theme in style file instead of "Theme.AppCompat.DayNight.NoActionBar".
Night mode will not work unless we use the Day Night theme in style. There for you can use default theme for your application to disable the dark mode.
<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>
</style>
try add this
<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light.DarkActionBar">
then this in layout
android:forceDarkAllowed="false"

Android action bar not reflecting color change

I've read numerous answers regarding changing the color of the action bar, but I can't seem to get it to work. Here's what I have:
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="Theme.AppCompat.Light">
<item name="android:windowBackground">#color/actionBarBackground
</item>
</style>
</resources>
I've also tried
<item name="android:Background">#F33</item>
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
You are changing the android:windowBackground not the background of your ActionBar.
In any case, starting with the AppCompat v21+, you can use a new way to customize your ActionBar.
All of your Activities must extend from AppCompatActivity
All of your themes (that want an ActionBar/Toolbar) must inherit from Theme.AppCompat.
Just use a theme like this:
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<!-- Set AppCompat’s color theming attrs -->
<item name="colorPrimary">#color/my_awesome_red</item>
<item name="colorPrimaryDark">#color/my_awesome_darker_red</item>
<!-- The rest of your attributes -->
</style>
The current version of AppCompat is 23. It requires API23 to compile the project.
The following seems to have done the trick. I found it here Change Background color of the action bar using AppCompat
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="Theme.AppCompat.Light">
<item name="android:background">#color/actionBarBackground</item>
<item name="background">#color/actionBarBackground</item>
</style>
However, now my android:label in my manifest file is being covered by the background color, so I added
<item name="android:displayOptions">showTitle</item>
<item name="displayOptions">showTitle</item>

AppCompat ActionBar Background Color

I have this style.xml inside my Android app:
<resources xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
<style name="OrangeTheme" parent="#style/Theme.AppCompat">
<item name="android:actionBarStyle" tools:ignore="NewApi">#style/OrangeTheme.OrangeActionBar</item>
<item name="android:windowActionBar">true</item>
</style>
<style name="OrangeTheme.OrangeActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#color/orange</item>
<item name="background">#color/orange</item>
<item name="android:backgroundStacked">#color/orange</item>
<item name="android:backgroundSplit">#color/orange</item>
<item name="android:titleTextStyle">#style/Theme.MyAppTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="Theme.MyAppTheme.ActionBar.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/black</item>
</style>
I have searched StackOverflow and Google, but nothing helped. I wasn't able to change the ActionBar background color.
Inside my MainActivity, I use this code:
public void restoreActionBar() {
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(mTitle);
}
I tried not to use AppCompat, but then my name has a lot of errors. It extends ActionBarActivity. If I change it to FragmentActivity I can't use getSupportActionBar() and without it my getActionBar(), is always null.
minSdkVersion 19
targetSdkVersion 21
So right now I am not able to change it. I tried renaming the parent of my style theme. I tried using andrioud:background and background. The only thing that is changing is when I use another parent like
Theme.App.Compat.Light or Theme.AppCompat.Light.DarkActionBar.
Does someone have an idea, how I could be able to change the colors and other stuff, on runtime?
With new AppCompat-v7 (v21) you can use new color theming attributes. See here.
Or alternatively you have to use <item name="actionBarStyle"> property (without prefix android).
To use background color with AppCompat, you need to also define the item name without the android: attribute.
for example:
<style name="MyActionBar" parent="Theme.AppCompat.Light">
<item name="android:background">#color/action_bar_background</item>
<item name="background">#color/action_bar_background</item> //<--background item without the android attribute
</style>
and then in your custom theme do the same thing for the custom actionbar style:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>

How to set background image for IcsSpinner and its drop down view resource using action bar sherlock in android

How to add style for IcsSpinner using action bar sherlock in android. If anyone know how to set different background image for IcsSpinner and Drop down view resource
<style name="AppTheme" parent="#style/Theme.Sherlock">
<item name="android:actionDropDownStyle">#style/DropDownNav</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView</item>
</style>
<style name="DropDownListView" parent="#android:style/Widget.Holo.Light.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background</item>
</style>
<style name="DropDownNav" parent="#android:style/Widget.Holo.Light.Spinner">
<item name="android:background">#drawable/spinner_background_ab</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel</item>
<item name="android:dropDownSelector">#drawable/selectable_background</item>
</style>
Check out ActionBar Style Generator

Resources