Android Views Palette Missing for Activity - android

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.

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

Does new activity need content and activity xml?

Since the latest changes, the main activity has an activity_main.xml and a content_main.xml.
I'm creating a new activity now in the same project but no matter how I create it, I can't get Android Studio to create both xml files for the new activity. This means that I can't remove the toolbar unless I do so programmatically. That's fine by me.
Ultimately, I'm just wondering if I should create both xml files for the second activity.... like:
activity_notmain.xml
content_notmain.xml
or should I just create the one layout file and remove the toolbar programmatically?
just right click on res>layout and go to new>activity>blank activity then enter name for activity and layout file it will automatically create both activity and content xml file

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.

Where is the layout file of my settings activity?

I used the Settings Activity template to create a new activity in android studio. After creating it, I cannot find the layout file of the activity anywhere. Where can I find the layout file? If there is no layout file for Settings Activity template, how can I change its contents?
Android studio also created a new folder called xml, does this have anything to with the settings activity?
Settings Activities typically use preferences defined in an XML file. These aren't exactly layouts, so they are usually placed in the xml resource subdirectory. Read more about preference-based settings screens on this page.
By default the Settings activity extends PreferenceActivity which has a standard layout. The layout is shown in the documentation
Nonetheless, if you want to change it, you can refer to this question

Categories

Resources