新建專案打開 activity_main.xml 圖形化編輯器報錯:
Failed to find the style corresponding to the id 2130772026
android.support.v7.internal.app.WindowDecorActionBar 實例化失敗。
ADT / Android Studio Layout Render 使用的 API Level 與專案 compileSdkVersion / targetSdkVersion 不匹配,導致主題樣式資源找不到。
styles.xml 將 parent="Theme.AppCompat.Light.DarkActionBar" 改為具體版本 parent="Base.Theme.AppCompat.Light.DarkActionBar"。android {
compileSdkVersion 34
defaultConfig {
targetSdkVersion 34
minSdkVersion 21
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1' // 遷移至 AndroidX
}
新專案建議直接使用 androidx 而非 android.support.v7。
切換 API Level 後,圖形化編輯器應正常顯示手機螢幕預覽,可拖拽元件。