Android Studio预览窗口隐藏求助:更新后仍无法显示
Hey there, I’ve run into this exact preview window issue before—total pain when you can’t visualize your layout without running the app. Let’s go through some tried-and-tested fixes that should get it back up and running:
Double-check the editor view toggle
When you’re editing your XML layout file, look at the top-right corner of the editor panel. You should see three options:Code,Split, andDesign. If you’re stuck onCodeonly, clickSplitorDesignto bring the preview back. Sometimes it’s just accidentally toggled off without you noticing.Invalidate caches and restart Android Studio
Corrupted cache files are a common culprit here. Head toFile > Invalidate Caches..., then select Invalidate and Restart. Let Studio fully reboot—this clears out wonky temporary files that might be blocking the preview.Verify layout compatibility with API 22
Since you’re targeting API 22, make sure your layout isn’t using components or attributes that were introduced in newer APIs. For example:- Replace modern Material components with AppCompat alternatives (e.g., use
androidx.appcompat.widget.AppCompatTextViewinstead of a plainTextViewif you’re using Material themes) - Avoid layout attributes like
android:foregroundTintwhich weren’t available until API 23 - Also, check the preview toolbar (if it becomes visible) to ensure you’ve selected an API 22 device for previewing
- Replace modern Material components with AppCompat alternatives (e.g., use
Check your Gradle configuration
Open your app-levelbuild.gradlefile and confirm:compileSdkVersionandtargetSdkVersionare set to at least 22- You have the AppCompat dependency included (e.g.,
implementation 'androidx.appcompat:appcompat:1.6.1'—this version works well with API 22)
After making any changes, sync your Gradle project and try the preview again.
Reset the Layout Designer state
If none of the above works, manually clear the layout editor’s cached state:- On Windows: Navigate to
C:\Users\<YourUsername>\.AndroidStudio<Version>\system\layout-designerand delete the folder - On Mac: Go to
~/Library/Application Support/Google/AndroidStudio<Version>/layout-designerand delete the folder
Restart Android Studio afterward—this forces the layout editor to rebuild its configuration from scratch.
- On Windows: Navigate to
内容的提问来源于stack exchange,提问作者Arboker

