Search code examples
androidandroid-layoutandroid-studioandroid-drawableandroid-layout-editor

How to refresh a resource in Android Studio without restarting?


I'm working on resizing and changing background images. However, each time I have to restart Android Studio so the Layout Preview will refresh the image.

Doesn't work:

  • Changing API level
  • Changing Preview orientation
  • Changing theme
  • Synchronizing project

What else can I do?

On Android Studio 2.2.2, Windows 10 64-bit on AMD A8-6410 with AMD Radeon R5 Graphics, 11 GB of RAM.


Solution

  • If you're on pre-Android Studio 2.2: just hit the refresh button on the menu bar of the layout editor.

    Otherwise:

    Go to the layout you're working on. Then, change any resource to an incorrect name.

    For example, if you have a button with this attribute:

    android:background="@drawable/button"
    

    Replace it with any random false resource:

    android:background="@drawable/thisIsSomethingVeryRandomAndDoesntExist"
    

    Then, you'll get something similar to this:

    image

    Click the "Refresh" (Sometimes "Clear Cache"), then go and undo the changes you did with the attribute. Voila!

    Sometimes even changing the orientation works.

    Source