androidmaterial-designmaterialcardview

com.google.android.material.card.MaterialCardView not displaying in android studio 3.5.3


preview of design using xml is not showing com.google.android.material.card.MaterialCardView, but its shown when we install the app.


Solution

  • 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.