Can't add any items to activity_main.xml in Android Studio

微笑、不失礼 提交于 2019-12-21 21:27:07

问题


In Android Studio, I can't add any items from Palette to activity_main.xml in Design view. It just won't let me drag and drop them. Any idea why this happens?

Here is the PrintScreen:


回答1:


According to new design method followed in android studio for android development you cannot add any elements to the activity_main.xml. Rather you should add them to content_main.xml.

You can learn more about it from this answer.




回答2:


You can stop it from happening.
Answered by BNK:

If you create a new project, you can choose Empty Activity template instead of Blank Activity. If you create a new activity, you can choose Empty Activity instead of Blank Activity too.

how do I create an Empty Activity with a Fragment?

You start by creating an activity using the "Empty Activity" template. Then, add a fragment class yourself or possibly via New > Fragment. Please understand that all of the "New >" options, for activities, fragments, etc., are all driven by templates. Those templates do what they do. If you do not want what they are generating, don't use them, and add the classes, resources, manifest entries, and such yourself. Personally, I almost never use those templates, because it's simpler IMHO just to create it all yourself than to rip out all the stuff you don't need that gets generated.




回答3:


I had same problem. In the design page, I saw error message "Render Error..." I click Android Studio->check for update->update and restart After android studio update, the drag&drop from Palette to design page works.



来源:https://stackoverflow.com/questions/33129629/cant-add-any-items-to-activity-main-xml-in-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!