简体   繁体   English

装订线中没有 XML 颜色预览

[英]No XML color preview in gutter

After trying just about everything, I cannot get the color preview to show in the XML editor in Android Studio.在尝试了几乎所有内容后,我无法在 Android Studio 的 XML 编辑器中显示颜色预览。 In my colors.xml file, I expect a line like <color name="colorAccent">#1AD270</color> to show a small square to the left of it in the gutter previewing the color.在我的colors.xml文件中,我希望像<color name="colorAccent">#1AD270</color>这样的<color name="colorAccent">#1AD270</color>预览颜色的装订线中在它的左侧显示一个小方块。

Weirdly, it only happens in this particular project.奇怪的是,它只发生在这个特定的项目中。 When I open other Android Studio projects, the gutter icons appear normally.当我打开其他Android Studio项目时,装订线图标正常显示。

I have completely reset my Android Studio settings, disabled/enabled gutter icons and changed the gutter background, none of which worked.我已经完全重置了我的 Android Studio 设置,禁用/启用了装订线图标并更改了装订线背景,但这些都不起作用。 Any help?有什么帮助吗?

Turns out that the color previews do not show up if you don't have an activity in your project.事实证明,如果您的项目中没有活动,则不会显示颜色预览。 After adding the first activity, the color preview icons suddenly appear.添加第一个活动后,颜色预览图标突然出现。 Weird!奇怪的!

Just to expand on zwh's comment , you bizarrely need to have a layout xml in the layout folder of the module.只是为了扩展zwh 的评论,您奇怪地需要在模块的layout文件夹中有一个布局 xml。

It doesn't need to be linked to an activity at all, or mentioned anywhere, just has to exist!它根本不需要与活动相关联,也不需要在任何地方提及,只需存在即可! I created one called dummy_layout.xml :我创建了一个名为dummy_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- If this file is deleted, colors.xml doesn't show colour gutter icons https://stackoverflow.com/a/65395717/608312 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM