简体   繁体   中英

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

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.

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" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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