preview of design using xml is not showing com.google.android.material.card.MaterialCardView, but its shown when we install the app.
-
Try to 'Invalidate caches & restart' – Viral Patel Jan 03 '20 at 06:32
-
No that is not working – Abraham Mathew Jan 03 '20 at 06:47
-
2Change your **app theme** from preview window to `Theme.MaterialComponents` or better and you'll get your result. – Jeel Vankhede Jan 03 '20 at 06:59
-
one more doubt, i have a loader inside cardview and on clicking the cardview, the cardview inflates.Is there some solution – Abraham Mathew Jan 03 '20 at 07:03
3 Answers
The theme on the layout preview windows needs to be or extend a Theme.MaterialComponents theme. Sometimes the theme in your layout preview doesn't reflect what's the actual theme of your app or view.
If you change the theme on your picker to a theme that is or Extends Theme.MaterialComponents the preview for the MaterialCardView should show.
The problem with this is that you just fixed for your machine and for a particular instance of Android Studio. Is very easy that config gets lost.
To avoid this and make it work on any machine you can place this on the root view of your layout file:
tools:theme="@style/YourMaterialComponentsTheme"
The tools
namespace is just for preview purposes. If you really want this theme to take effect when you run the app on your device replace tools
with android
, but I wouldn't do this unless you know what you're doing in terms of themes and styles.

- 14,089
- 2
- 50
- 43
make sure you are using this dependency in your build.gradle(Module:app)
implementation 'com.google.android.material:material:1.0.0'
or any version of this dependency.

- 554
- 1
- 7
- 23
-
i am using this one com.google.android.material:material:1.1.0-alpha08 – Abraham Mathew Jan 03 '20 at 06:46
-
my suggestion is don't use alpha version. if you are using alpha then make sure you use correct theming – Hasan Khan Jan 03 '20 at 06:51
Method-1 Invalidate cache & Restart
Method-2 Make a backup of project delete .idea folder & .iml file and re-import project

- 148
- 11