1. 程式人生 > >AndroidStudio Unknown attribute(在xml中沒有了程式碼提示)

AndroidStudio Unknown attribute(在xml中沒有了程式碼提示)

問題

在這裡插入圖片描述

如上圖所示,編寫xml的時候提示:Unknown attribute in xml and Namespace not found

真的氣死人,升級到AndroidStudio3.2.1,sdk28以後問題成堆出現。

解決方案

下面是百度最多的兩個解決方案,然而對我沒什麼用。

1.省電模式

File --->power save mode--->取消勾選

2.刪除.idea和.iml,然後ReBuild

https://bbs.csdn.net/topics/391846404

Finally, deleting .idea folder and all .iml files from the project, restarting Android Studio and rebuilding gradle did the trick.
Autocomplete in XML support library is working again.
Probably checking out files from Version Control or copying all the source files in a new project would do the trick aswell.
這是stackoverflow上大神的回覆,就是刪除.idea資料夾和所有的.iml檔案,然後重啟as,重新build project,經測試時有效果的。

如果上面都不行,試試第三個,我是第三種方案解決的。

3.compileSdkVersion

就是sdk版本的問題。
https://blog.csdn.net/f327888576/article/details/51718846

我的是compileSdkVersion 28,之前一直好好的,看到這個解決辦法,我改為compileSdkVersion 27,然後神奇的一幕出現了,xml裡面Unknown attribute的提示消失了,然後程式碼提示也有了。
sdk檔案損壞了???很奇怪!!!
然後我解除安裝sdk28,再重新安裝,改回compileSdkVersion 28,就沒問題了。

如下圖:
先取消勾選,然後點選apply解除安裝。
勾選之後,點選apply就是安裝。
在這裡插入圖片描述