When I use this theme everything is OK.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
But I wanted to use custom toolbar so I changed app theme to Theme.AppCompat.NoActionBar.
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
The problem is that background of app now has the same color as a toolbar.
Before this change it was white.
When I change android:windowBackground it's only apply to Navigation Drawer.
How to make background color (marked by red arrow) white again ?
You need to change background color from xml file
and try this style for no actionbar
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="android:typeface">monospace</item>
<item name="windowNoTitle">true</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:actionModeBackground">#color/colorPrimary</item>
<item name="android:textSize">#dimen/common_text_size</item>
</style>
Solved the issue by changing only colorPrimary.
<style name="AppTheme.NoActionBar">
<item name="colorPrimary">#color/colorWhite</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Related
I have tried to change the hamburger icon color from black to white following this: How to change Toolbar home icon color, however the icon will not change its color.
Here is the style I created:
<style name="WhiteHamburguerIcon" parent="AppTheme">
<item name="android:textColorSecondary">#color/white</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Then I applied the style to the toolbar:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:theme="#style/WhiteHamburguerIcon"
app:popupTheme="#style/AppTheme.PopupOverlay"
app:titleTextAppearance="#style/Toolbar.TitleText" />
The activity is using this style:
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
The back arrow is white also the overflow button. What can I do to achieve this?
parent from your style icon must be "#style/Widget.AppCompat.DrawerArrowToggle".
The "WhiteHamburguerIcon" is an item style, so just add it to the activity style:
<item name="drawerArrowStyle">#style/WhiteHamburguerIcon</item>
I think you should change your "styles.xml" file as
<style name="MyMaterialTheme" parent="MyMaterialTheme.Base">
</style>
<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
</style>
<style name="DrawerArrowStyle" parent="#style/Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#android:color/white</item>
</style>
Happy coding...
I don't know if is related with git but after committing my project using git, every Activity's background color is changed even when I create a new Activity.
Why?
My style file
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.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="drawerArrowStyle">#style/MyDrawerArrowToggle</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="MyDrawerArrowToggle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="color">#color/toolbar_text_color</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="colorControlNormal">#color/textColor</item>
</style>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"></style>
</resources>
<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="drawerArrowStyle">#style/MyDrawerArrowToggle</item>
</style>
I changed "Theme.AppCompat.NoActionBar" to "Theme.AppCompat.Light.NoActionBar".
It is worked.Thanks everyone....
Here is the mistake you are using dark theme
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="colorControlNormal">#color/textColor</item>
I'm applying this this to my base activity in manifest file.
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds" tools:targetApi="lollipop">true</item>
<item name="android:statusBarColor" tools:targetApi="lollipop">#color/darkRed</item>
</style>
But my status bar in base activity appears to be in blue colour. What am I suppose to do.
This is because in style.xml file you have not use colorPrimaryDark to change status bar color.
So if you are using material design to create your application then please refer this guidelines as shown below:
https://material.google.com/
https://developer.android.com/training/material/index.html
http://www.androidhive.info/2015/04/android-getting-started-with-material-design/
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds" tools:targetApi="lollipop">true</item>
<item name="android:statusBarColor" tools:targetApi="lollipop">#color/darkRed</item>
</style>
Try this.
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorPrimary">#color/colorPrimary</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">#color/colorAccent</item>
</style>
I am encountering a very strange error in my application. It shows the text of a button, but not the button itself. Here is a screenshot:
I then checked the Theme Editor to see what might happen, and what I get in there looks like this:
The editor seems to be unable to render Material design correctly, no matter if it is dark or light. When I switch it to Holo for example, everything works fine.
My AndroidStudio is up to date, I have no idea what is going on, but I will provide my styles.xml files here as well:
v21\styles.xml
<resources>>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="preferenceTheme">#style/PreferenceThemeOverlay.v14.Material</item>
<item name="preferenceStyle">#style/PreferenceThemeOverlay.v14.Material</item>
</style>
<style name="MyActionBarTheme" parent="android:Widget.Material.Light.ActionBar">
<item name="android:background">#color/colorAccent</item>
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="#android:style/TextAppearance.Material.Widget.ActionBar.Title">
<item name="android:textColor">#color/colorPrimary</item>
</style>
<style name="AppTheme" parent="android:Theme.Material.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:colorBackground">#color/background_material_light</item>
<item name="android:colorPrimary">#color/primary_material_light</item>
<item name="android:actionBarStyle">#style/MyActionBarTheme</item>
<item name="preferenceTheme">#style/PreferenceThemeOverlay.v14.Material</item>
<item name="preferenceStyle">#style/PreferenceThemeOverlay.v14.Material</item>
</style>
</resources>
styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.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="android:colorBackground">#color/background_material_light</item>
<item name="android:actionBarStyle">#style/MyActionBarTheme</item>
<item name="preferenceTheme">#style/PreferenceThemeOverlay.v14.Material</item>
<item name="preferenceStyle">#style/PreferenceThemeOverlay.v14.Material</item>
</style>
<style name="MyActionBarTheme" parent="Widget.AppCompat.ActionBar">
<item name="android:background">#color/colorAccent</item>
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/colorPrimary</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="preferenceTheme">#style/PreferenceThemeOverlay.v14.Material</item>
<item name="preferenceStyle">#style/PreferenceThemeOverlay.v14.Material</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
Ok, I finally found out what was causing the error: My main activity was extending AppCompatActivity (This was generated by Android Studio in an earlier stage). When I changed this to extend FragmentActivity, everything worked like a charm.
This solution solved both the button as well as the theme editor problem. I do not know why theme editor would not show the custom material design when my main application does not extend the correct class, but this small piece of code changed fixed all my issues.
Status bar of my app is not seem as clear or it appears with some shadow.
This is how my status bar looks:
And it should appear like this:
Why it isn't looking like this?
style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBarOverlay">false</item>
<item name="windowActionBar">false</item>
<item name="android:windowBackground">#android:color/white</item>\
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
What's wrong with this? Please help..
Delete this line
<item name="android:statusBarColor">#android:color/transparent</item>
from your values-v21/styles.xml
If you are in android 5 or later you can set the elevation of the actionbar to 0 by below code
getSupportActionBar().setElevation(0);
If not 5 or higher then add below style in your theme
<style name="MyAppTheme" parent="android:Theme.Holo.Light">
<item name="android:windowContentOverlay">#null</item>
</style>