Stop Android Studio making content_main.xml - android

Since build 1.4, I've been getting content_main.xml every time I create a blank activity. It seems like Android Studio makes an activity_main.xml and then contains the content_main.xml inside. But I just do not get why this would be helpful. Is there a setting to turn off this behavior?

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.

Related

Content xml is not getting created for Basic activity

While creating any activity(other than empty) in android studio it is creating only activity xml, using Android Studio 3.1.4, Kindly help.
Empty activity default contains only a single layout file
Read this
Activity template
This template creates an empty activity and a single layout file with sample text content. It allows you to start from scratch when building your app module or activity.
But you can create the content layout separately then include into the main activity.
As my understanding, the activity_main xml file created by wizard is the content xml file when create Basic Activity.
Then you could modify the activity_main xml to fulfil your requirment.
According to the documentation of Android Studio, activity_main.xml will affect how global UI of Activity is designed and works. But content_main.xml will affect the contents in the activity_main.xml.
Since a Basic Activity,Empty Activity doesn't have much content, thus the content_main.xml is not created for those. If you create a Navigation Drawer Activity, Studio will create both app_bar_main.xml , content_main.xml and activity_main.xml

Why Android Studio doesn't create content_main.xml every time when I create new project?

When creating new project, sometimes Android Studio creates activity_main.xml and content_main.xml, but sometimes it creates just activity_main.xml and not content_main.xml. I can't find the logic, under which condition it chooses which files to create. Can anyone explain it, please?
When you create a new activities, you can choose different options, two of them are Blank Activity (if I recall properly) and Empty Activity. The difference between them is that one is based in the modern Android approach, based on Fragments.
Therefore, activity_main.xml is simply the Activity layout containing a container (FrameLayout most probably) and content_main.xml is the layout for a Fragment put into this container somewhere within MainActivity.java.
Answer based on https://stackoverflow.com/a/33415349/6166978

Content_main.xml missing

I am new to Android Studio. Following the tutorial given by developer.android I have created a new project. They asked to create a blank activity and as there is no one such, I have used Empty Activity as the template. Then the tutorial said that there will be a content_main.xml inside res/layout folder, but I didn't find one. Did I build the correct Application? What probably may be the wrong? Thanks in advance.
content_main.xml file will be generated when you choose "blank activity" . This activity will be having floating button by default at the bottom of the screen.
But when you choose "empty activty" then content_main.xml won't be generated and it won't be having floating button , but just simple activity.
So for your tutorial choose "blank activity" and then your tutorial will run fine
You need to select basic activity when creating a project. that will give you the 2 files content_main.xml and activity_main.xml
content_main.xml is used to handle the contents of the activity(like buttons, textView etc). So when we choose an empty activity, there are no components and hence the layout content file i.e. content_main.xml is not created. If you choose a blank activity there will be a floatingactionbutton component and hence there will be a content_main.xml created. So hopefully this will solve your problem. You can delete the floatingactionbutton later if you want your activity to be blank.
Try to close and reopen the Android Studio. I hope this works!
On the top right corner of the android studio code there is a search icon.
Click that and type: content_main.xml
You'll get the file over there open it.

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

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:
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.
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.
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.
Check ConstraintLayout properties:
layout width and layout height should be "match parent", not "wrap content".
It works for me.
While you have marked a witget the editor don't let you drag.

Android Views Palette Missing for Activity

Ok i created a new project in Eclipse for Android. My MainActivity is what was given to me. It has an activity_main.xml in the res.layout folder that i can drag and drop widgets onto the activity.
I created a new Activity called SurveyActivity but I can not find the xml file that allows me to use the palette.
Did i do something wrong when creating the activity or is there more that i need to do to get this to work?
Thanks
I Assume you created a class(and not an Activity, which can be done with ADT 20) and extended Activity. Then you have to create a layout xml by your own. Right click on te layout folder -> new -> Android xml file. Set this layout in your setContentView() of your Activity.
And don't forget to register that Activity in your Manifest.

Categories

Resources