i using android studio to start develop apps, but i have some question about "Select Theme" in android studio. First, i noticed i select "NoActionBar" option, the layout will be like
The statusbar has no color, but after when i change to "AppTheme", the layout became
I had double check the code in styles.xml, but there are no changes. I really can't figure out about this. Can anyone explain this to me? Thank in advance.
**I have figured out actually select theme only the preview, it doesn't change my XML layout.
you will find this in styles.xml
<!-- 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>
In your layout, two things are happening here
1. Your layout have a toolbar in its xml. So toolbar always showing.
2. the above pic will give you an idea about how the material theme isapplying with colors.
Hope this helps you.
check the colorPrimary and the colorPrimaryDark in your color.xml file
Related
Problem :
There was no problem when app was using
Theme.MaterialComponents.Light.NoActionBar
But was not using any MDC elements in Layout like (TextInputLayout etc).
Then i replaced Editext with TextInputLayout and Button with Material Button.
Now here the problem comes.
When i run my app, i see the screen goes blank. Just pure white.
I checked Layout isses.
I found there're 7 warnings and 2 errors(Render problem).
The Render problems are as -
Path.op() not supported. (As was it suggests i refreshed the layout many times. Doesn't work)
java.awt.geom.IllegalPathStateException: missing initial move to in path definition
This is what i have tried -
Downgrading my MDC dependency (how to solve render problem Path.op() not supported?)
Clean project, rebuild and restart Android studio
Please help me to solve this strange issue.
I want to use MDC in my project.
Thank you.
I would suggest you should first make use of the Bridge then, gradually override the parent theme attributes based on your requirement design.
In AndroidManifest.xml
android:theme="#style/MyMaterialTheme"
Then under style.xml. it would like something like
<style name="MyMaterialTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorPrimary</item>
<item name="android:windowBackground">#color/white</item>
<item name="toolbarStyle">#style/BlueToolbar</item>
</style>
try referring reference , reference
Simple solution is make your theme extend a Bridge theme :) I hope this helps
I just got android studio and I have some questions as my screen is different from the tutorial on lynda.com . The design tab for my content_main.xml file is just a blue square
However, the tutorial has this screen instead.
. This seems to fix itself when I closed the project and reopened it. However, instead of Hello World the tutorial has in the middle of the screen, I have android...Coordinator Layout as seen below. What have I done wrong as I literally just downloaded Android Studio...
make sure your styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Base.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>
Make sure style is (parent="Base.Theme.AppCompat.Light.DarkActionBar">)
I'm actually creating an app an I would like to use Material Theme Light.
So I put the line android:theme = "#android:style/Theme.Material.light"
on the manifest and no errors are displayed.
However when launching the app on my phone it crashes at launch although no errors are displayed in my xml/java sources.
I'm sure this line is the cause, because when I change the manifest to #style/AppTheme, it works and lauches.
It's driving me crazy, I need your help please.
It depends on your activity, What does your activity extend from? If it extends from AppCompatActivity you can't set material theme.
you should set AppTheme as your theme android:theme="#style/AppTheme"
and in style file, set AppCompat Theme as your parent:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Try this it will work click on values in resources than open styles.xml file and change this
with following
i was getting the same issue and it is due to the update in the material lib
I'm making my app ready for Android 5.0, I'm using the latest compatibility library, here is what my style looks like.
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/theme_accent</item>
<item name="colorAccent">#color/theme_accent_secondary</item>
</style>
<style name="AppThemeDark" parent="Theme.AppCompat">
<item name="colorPrimary">#color/theme_accent</item>
<item name="colorAccent">#color/theme_accent_secondary</item>
</style>
</resources>
(The ActionBar color is being set programmatically.)
Now, I want the overflow/popup menu to have the dark background like it had in the holo implementation, but I can't get it to work, here is what it looks like:
I have tried setting the popupMenuStyle but it didn't work.
How can I make the popup menu darker?
Stop using the ActionBar. If you want a ToolBar to be set up like an ActionBar, follow this guide on the android-developers blog.
It actually mentions your use case at Dark Action Bar and provides this code:
<android.support.v7.widget.Toolbar
android:layout_height=”wrap_content”
android:layout_width=”match_parent”
android:minHeight=”#dimen/triple_height_toolbar”
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
Not a full answer but what I found so far:
In past versions you needed to specify a drawable (Check https://github.com/StylingAndroid/StylingActionBar code and tutorials)
Apparently, now that is a color. To modify it you need to do specify the following theme:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
<item name="android:actionBarPopupTheme">#style/popupNew</item>
</style>
<style name="popupNew" parent="android:ThemeOverlay.Material.Light">
<item name="android:colorBackground">#color/red</item>
</style>
</resources>
This works correctly if the theme applied to the app is just this.
If I add android:actionBarPopupTheme to my existing theme, it doesn't work. I am trying to figure out why.
Solved my problem by using this style:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/theme_accent</item>
<item name="colorAccent">#color/theme_accent_secondary</item>
<item name="actionBarStyle">#style/AbStyle</item>
<item name="actionModeBackground">#color/actionmode_bg</item>
</style>
<style name="AbStyle" parent="Widget.AppCompat.Toolbar">
<item name="elevation">2dp</item>
<item name="displayOptions">homeAsUp|showTitle</item>
<!--showHome-->
</style>
<style name="AppThemeDark" parent="Theme.AppCompat">
<item name="colorAccent">#color/theme_accent_secondary</item>
<item name="actionBarStyle">#style/AbStyle</item>
</style>
I had to use Widget.AppCompat.Toolbar as the parent actionBarStyle
Add the property popupTheme to your toolbar:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/color_primary"
app:theme="#style/Theme.AppCompat.Light"
app:popupTheme="#style/Theme.AppCompat" />
Or define a new style for your toolbar:
<style name="MyToolBarStyle" parent="Widget.AppCompat.Toolbar">
<item name="android:background">#color/green</item>
<item name="popupTheme">#style/Theme.AppCompat.Light</item>
<item name="theme">#style/Theme.AppCompat</item>
</style>
This question has already been answered for styling via XML, but I'm adding an explanation here of how to work out the solution to this and similar styling questions yourself.
First, this is the solution when using AppCompat. To your App's style.xml add actionBarPopupTheme to your theme:
<style name="Theme.MyTheme" parent="#style/Base.Theme.AppCompat.Light.DarkActionBar">
...other stuff here
<item name="actionBarPopupTheme">#style/Theme.MyTheme.ActionBarPopupTheme</item>
</style>
<style name="Theme.MyTheme.ActionBarPopupTheme" parent="#style/ThemeOverlay.AppCompat.Light">
<item name="android:textColor">#android:color/white</item>
<item name="android:background">#android:color/black</item>
</style>
Here's the steps I took to arrive at this solution (it takes a bit of detective work as the Android documentation is poor):
Open your App's style.xml in Android Studio
On the line where you App's theme is defined, put your screen cursor in the parent theme (e.g. click in #style/Base.Theme.AppCompat.Light.DarkActionBar) then press F4. This should take you to the source code for the style in the appcompat library.
Within this style I saw this line:
< item name="actionBarPopupTheme">#style/ThemeOverlay.AppCompat.Light< /item>
This looked like a possible place to change the theme of the popup. I searched for "actionBarPopupTheme" in the poor
Android developers documentation and found "Reference to a theme that should be used to
inflate popups shown by widgets in the action bar". So this was worth playing with.
I copied the appcompat line containing "actionBarPopupTheme" to my style.xml then in this line replaced the item's theme reference (the bit in bold above) with Theme.MyTheme.ActionBarPopupTheme.
In my style.xml I created my new style named Theme.MyTheme.ActionBarPopupTheme. I used the same parent that was used in the style I copied from the appcompat source (the bit in bold above).
To ensure my new popup style was working, I changed the parent style to ThemeOverlay.AppCompat.Dark then ran and tested the code on a device. The popup style changed, so now I knew my overriding of actionBarPopupTheme was the correct thing to do. Then I changed back to ThemeOverlay.AppCompat.Light.
The next challenge is to work out what item names to override in Theme.MyTheme.ActionBarPopupTheme. I changed the text and background colours. To find the correct item names that change the style of something can be tricky in some cases. One way to find less obvious style item names is to look through the style definitions in the appcompat xml file (the one you opened when pressing F4 in the 2nd step above), continually descending into parent styles (F4 again!) until you find something that may do what you want. Google searches will help here too.
Each "layout" I set a white background and "Manifest" I set Theme.Light.
Still receives a gray background instead of white. Why?
Edit:
Manifest.xml
android:theme="#android:style/Theme.Light.NoTitleBar">
Layout
android:background="#android:color/white"
Theme.Light does not mean that it will be white. It just means that it will be light, not dark :P This is not theme.white.
Each device manufacturer can customize Android OS on his phone for example to preferred colors and look & feel. In particular he can define styles for his Android implementation - Light and dark. Thanks to that your app may look differently on various devices, however it will always fit the style used on this device (every app in style Theme.Light will have grey background on this device, unless you set android:background="#android:color/white" )
Your device's manufacturer defined style Theme.Light as style with grey background.
Hope that I am clear - otherwise do not hesitate to ask
I had the same issue until I changed #android:color/white to explicit android:background="#FFFFFF". Weird though...
Since it's an old question this might have another solution already but anyway one can just enter the AppTheme style tag in styles.xml, you can do so by pressing the ⌘cmd key and clicking on your theme declaration in the manifest.
Over there add this line with your preferred color -
<item name="android:windowBackground">#color/white</item>
This line basically overrides the theme's default background value.
Example -
<!-- Base application theme. -->
<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="android:colorControlActivated">#color/black</item>
<item name="android:windowBackground">#color/white</item>
</style>