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
Related
Whenever I use MaterialButton, I get the following exception in the xml preview:
java.lang.IllegalArgumentException: java.lang.ClassCastException
I have upgraded to android studio 3.4 and to com.google.android.material:material:1.1.0-alpha05
Version 1.0.0 works but any 1.1.x doesn't.
Is this a problem with the IDE or the library?
-
For reference, the full stacktrace:
java.lang.ClassCastException#d8dc5d1
at sun.reflect.GeneratedMethodAccessor893.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at android.animation.PropertyValuesHolder_Delegate.callMethod(PropertyValuesHolder_Delegate.java:108)
at android.animation.PropertyValuesHolder_Delegate.nCallFloatMethod(PropertyValuesHolder_Delegate.java:143)
at android.animation.PropertyValuesHolder.nCallFloatMethod(PropertyValuesHolder.java)
at android.animation.PropertyValuesHolder.access$400(PropertyValuesHolder.java:38)
at android.animation.PropertyValuesHolder$FloatPropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:1387)
at android.animation.ObjectAnimator.animateValue(ObjectAnimator.java:990)
at android.animation.ValueAnimator.animateBasedOnTime(ValueAnimator.java:1339)
at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1471)
at android.animation.ValueAnimator.pulseAnimationFrame(ValueAnimator.java:1490)
at android.animation.AnimatorSet.pulseFrame(AnimatorSet.java:1163)
at android.animation.AnimatorSet.handleAnimationEvents(AnimatorSet.java:1146)
at android.animation.AnimatorSet.doAnimationFrame(AnimatorSet.java:1046)
at android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:146)
at android.animation.AnimationHandler.access$100(AnimationHandler.java:37)
at android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:54)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:947)
at android.view.Choreographer.doCallbacks(Choreographer.java:761)
at android.view.Choreographer_Delegate.doFrame(Choreographer_Delegate.java:66)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:563)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:425)
at com.android.layoutlib.bridge.BridgeRenderSession.render(BridgeRenderSession.java:120)
at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:151)
at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:133)
at com.android.tools.idea.rendering.RenderTask.lambda$null$8(RenderTask.java:755)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
EDIT This happens only when the button style is not set OR the defaulted:
#style/Widget.MaterialComponents.Button
Setting as unelevated style works for example, so as a work around I'm using the tools namespace to show unelevated button style.
Edit 2 the app theme parent is already correctly set as Theme.AppCompat.Light.DarkActionBar. This is an IDE issue as it is running well on my emulator and device. I have also done a clear cache & invalidate, clean build, rebuild... (the standard things we do when faced with weird IDE problems)
Edit 3 Still no luck with the latest A.S. 3.4.1!
Update3: This is finally fixed in Studio 3.5beta2! We did it guys! 🥳
Update2: I've filed an issue here: https://issuetracker.google.com/issues/132562197. Please star for visibility.
Update: This is a cleaner workaround since we don't have to litter tools:style throughout our xml layouts. This has stopped working for me for no apparent reason, I've had to revert to my original workaround described below.
Here's a workaround till we get an actual fix, based on Gautham's discovery:
Add this style to your styles.xml:
<!-- For the sake of xml preview not breaking -->
<style name="UnelevatedButton" parent="Widget.MaterialComponents.Button.UnelevatedButton">
</style>
Add it to your Buttons like so:
<Button
...
tools:style="#style/UnelevatedButton"
style="#style/ActualButtonStyle"
/>
Note that the ordering of the two is important, the tools line needs to come first.
You can update your UnelevatedButton to match your ActualButtonStyle for the sake of having previews consistent with your actual runtime buttons.
I'm attempting to reproduce this issue currently, but I need more information. My current hypothesis is that it's related to button elevation (based on the animation calls in the stacktrace), which is also why unelevated button works as expected.
Could you please file an issue at https://issuetracker.google.com/issues/new?component=439535&template=1121918 with the component name and description, as well as the information requested there?
amitav13's solution has one major problem, when you reformat the code the default rules will rearrange all the attributes and then everything breaks again.
Instead, until this is fixed, my proposal is to create a separate application theme for using in preview windows, in this example this Theme is called AppTheme.PreviewFix.
Simply select this theme in Preview / Design panes.
attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="buttonStyle" format="reference" />
</resources>
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.MaterialComponents">
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryDark">#color/primaryDarkColor</item>
<item name="colorSecondary">#color/secondaryColor</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="buttonStyle">#style/AppTheme.Button</item>
</style>
<style name="AppTheme.PreviewFix" parent="AppTheme">
<item name="buttonStyle">#style/AppTheme.Button.PreviewFix</item>
</style>
<style name="AppTheme.Button" parent="Widget.MaterialComponents.Button"/>
<style name="AppTheme.Button.PreviewFix" parent="Widget.MaterialComponents.Button.UnelevatedButton"/>
</resources>
my_layout.xml
<com.google.android.material.button.MaterialButton
style="?buttonStyle"
...
</com.google.android.material.button.MaterialButton>
Set your application theme from AppCompat to MaterialComponents such as below:
Use below style:
<style name="AppTheme" parent="Theme.MaterialComponents.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>
instead of
<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>
I had the same problem, I've downloaded another version of Android Studio.
It's Working Fine on A.S. 3.6 Canary 3...
I'm Using API 29, and material_version = '1.1.0-alpha08'
Download it here
The last working version for my earlier Android Studio was material_version = '1.0.0'.
But it didn't have some of the new material component features, so Instead of rolling back, I decided to Update Android Studio.
Do what best suits your needs.
Cheers.
After updating old android project to be able to build project with Android Studio 3.2.1, all popups became white.
All AlertDialog, ProgressDialog, Spinner got white background and white text.
If i change theme in the app, some text become readable but whiteness persist.
I solved some of them by hacks like this:
progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.DKGRAY));
but this doesn't work everywhere.
What can be the cause?
This is first time i work with android in seven year, i was doing iOS before, so this is new territory for me.
Update:
Comments helped to pinpoint that issue was regarding themes.
Now, challenge was digging out what was causing white backgrounds.
I had to set parent to my custom attribute:
parent="Base.Theme.AppCompat"
So in my custom theme there was this attribute: android:alertDialogTheme
<style name="CustomMobileTheme.Base.Black" parent="Base.Theme.AppCompat">
<item name="android:alertDialogTheme">#style/Theme.AppCompat.Dialog.Alert</item>
<item name="android:colorPrimary">#color/actionBarColorBlackTheme</item>
<item name="android:statusBarColor">#000000</item>
That was making all this mess. I have no idea what android:alertDialogTheme does, it is not specified in Spinner documentation and i had to manually comment out about 200 attributes in the theme, to dig out this culprit and spend about 13 hours of my private time. I wish to the developer who made this suffer some bad karma.
All AlertDialog, ProgressDialog, Spinner got white background and white text.
It may Becuase of "colorAccent" in your application theme is white.
Please check your theme for "colorAccent". If not specified then please specify with color which you want. check below code.
<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>
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 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
I have been searching for the solution for the last several days but could not find one.
I need to change the background color of the right pane (I know how to change the color of the left parent preference). I created a new theme in manifest file.
<activity android:name=".PreferenceWithHeaders"
android:label="#string/app_name"
android:theme="#style/PreferencesTheme">
</activity>
Below is the PreferencesTheme portion of styles.xml
<style name="PreferencesTheme" parent="android:Theme.Holo">
<item name="android:windowBackground">#drawable/background</item>
</style>
I am, however, unable to change the default gray background color of the child PreferenceScreenwhich is on the right. Please take a look at the picture.
I tried different things but they don't have any impact on the background color. Any pointers will be deeply appreciated!
I had this same issue not long ago; couldn't figure it out at the time, even after trying many of the solutions here. Finally stumbled upon a fix after running into a similar issue.
I just finished writing a blog post about it that explains in more detail, Fixing empty white space issues with Android ListViews, but basically you should be able to get rid of the white space by setting overScrollFooter to #null.
As overScrollFooter is only available in Android 2.3.3+ (API Level 10+), you'd have something like this:
res/values/styles.xml
<style name="MyListView" parent="#android:style/Widget.ListView">
</style>
res/values-v10/styles.xml
<style name="MyListView" parent="#android:style/Widget.ListView">
<item name="android:overScrollFooter">#null</item>
</style>
And of course update your PreferencesTheme to use it:
<style name="PreferencesTheme" parent="android:Theme.Holo">
<item name="android:windowBackground">#drawable/background</item>
<item name="android:listViewStyle">#style/MyListView</item>
</style>