英文:
com.google.android.material.card.MaterialCardView not displaying in android studio 3.5.3
问题
使用XML预览设计时,com.google.android.material.card.MaterialCardView不显示,但在安装应用程序后显示。
英文:
preview of design using xml is not showing com.google.android.material.card.MaterialCardView, but its shown when we install the app.
答案1
得分: 6
布局预览窗口上的主题需要是或扩展为Theme.MaterialComponents主题。有时,您的布局预览中的主题可能不反映您的应用程序或视图的实际主题。
如果您将选择器上的主题更改为是或扩展为Theme.MaterialComponents的主题,则MaterialCardView的预览应该显示。
问题在于,这仅适用于您的计算机和特定的Android Studio实例。配置很容易丢失。
为了避免这种情况,并使其在任何计算机上都能正常工作,您可以将以下内容放在布局文件的根视图中:
tools:theme="@style/YourMaterialComponentsTheme"
tools
命名空间仅用于预览目的。如果您真的希望在设备上运行应用程序时使此主题生效,请将tools
替换为android
,但除非您在主题和样式方面知道自己在做什么,否则我不建议这样做。
英文:
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.
答案2
得分: 5
确保你在你的 build.gradle(Module:app) 文件中使用了这个依赖项:
implementation 'com.google.android.material:material:1.0.0'
或者使用这个依赖项的任何版本。
英文:
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.
答案3
得分: 0
方法-1
使缓存无效并重新启动
方法-2
创建项目备份
删除.idea文件夹和.iml文件,然后重新导入项目
英文:
Method-1
Invalidate cache & Restart
Method-2
Make a backup of project
delete .idea folder & .iml file and re-import project
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论