com.google.android.material.card.MaterialCardView在Android Studio 3.5.3中未显示。

huangapple go评论81阅读模式
英文:

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.

see here

答案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

huangapple
  • 本文由 发表于 2020年1月3日 14:22:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/59574057.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定