问题
After trying just about everything, I cannot get the color preview to show in the XML editor in Android Studio. 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.
Weirdly, it only happens in this particular project. When I open other Android Studio projects, the gutter icons appear normally.
I have completely reset my Android Studio settings, disabled/enabled gutter icons and changed the gutter background, none of which worked. Any help?
回答1:
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!
回答2:
Just to expand on zwh's comment, you bizarrely need to have a layout xml in the layout folder of the module.
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:
<?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" />
来源:https://stackoverflow.com/questions/59122742/no-xml-color-preview-in-gutter