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.
Related
I'm using Android Studio 2.1 and there is no Blank Activity option.
I've seen people asking about this, and the general advice was "make one yourself".
The thing is that I know nothing about Android development so I'm following this tutorial http://developer.android.com/training/basics/firstapp/creating-project.html that should take me through the basic steps (at least it seems that it will do that). So I'm trying to keep things in line with what they do there.
So should I go with Empty Activity or Basic Activity? I tried them both and from what I undestand there are little differences between them, but Empty Activity sounds more like a clean startup activity than Basic. I don't know.
What should I do?
Empty Activity is the same as Blank Activity. It will gives you .xml file that will be your layout where you put your Buttons or EditTexts and .java file where you will code your activity.
But Basic Activity will gives you two .xml files, the main_activity.xml that contain FloatingActionButton and a ToolBar and it will include the second .xml where you will put your Buttons and one .java file .
If you are new at android developing start with Empty Activity it's more simple to understand
If you want to keep things in line with what they do there, you should go with Basic Activity because in the third step of that tutorial you'll need content_my.xml which won't be generated if you choose Empty Activity at start (of course you can put your code in activity_main.xml which is pretty the same thing). So if you only want to go in line with the tutorial you choose Basic Activity. The difference between previous Blank Activity and current Basic Activity is the extra code generated in your activity like:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
I had the same question so I've compared the old blank activity template (according to a video tutorial I watched) with the 'empty' and the 'basic' activities templates of the new Android Studio.
The empty activity has only 2 options: "Activity Name" and "Layout Name".
Meanwhile Basic activity has 4 options, just like the "blank activity" template of the old Android Studio version as you can see below:
So, I would go with the basic template and manage the extra code until I need it.
If you go with BaseActivity, it is also kind of empty activity. It would have only a root element in its layout. So you can start with any of the Basic or Empty.
Basic Activity comes with FloatingActionButton and menu layout. Empty Activity does not contain FloatingActionButton and menu xml layout, although you can add them manually when you feel so. What I feel is that Basic Activity is preferable because when you created Empty Activity and want to add menu in your activity it become rather difficult to add menu xml layout manually. I have personally encounter problems while adding menu xml manually.
Select File --> Settings
Select "Plugins" from that window
1.) Android NDK Support
2.) Android Support
check there any Tick Mark. Make Tick mark them, if no tick Marked . Then Rebuild Your App. or Close android studio and reopen
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.
I am new to Android App development. I have Android Studio 1.4. In my layout folder I have two XML files (content_main.xml and activity_main.xml). I have been following Bucky's tutorial and he just has the activity_main.xml. Which one should I use?
Unlike previous version, the new API 23 comes with the coordinatorLayout and stuff and just to make them simple to use android has distinguished activity's layout into two different layout i.e. content_main.xml & activity_main.xml.
I'll explain what they are for:
activity_main.xml
this xml file is used to display coordinatorLayout, tabLayout, floatingActionButton, viewPager etc..
content_main.xml
This xml file is use to display your stuff i.e. what you want to display to users.
So, if you are just asking in which xml you have to put your stuff, content_main.xml is the one....
I think the content_main.xml is a part of activity_main.xml.
Because there is include layout="#layout/content_main" in the activity_main.xml.
Android Studio 1.4 gives a default new option of content_main.xml in the activity. actually activity load the xml file of activity_main.xml for your layout. content_main.xml is the part of main.xml.
you can use both for layout,but main.xml is necessary for your Activity. its a option to choose the content_main.xml for design of layout.
Hope you get it.
The activity_main.xml is the "outer" part of the activity layout (toolbar, action button, etc.) and content_main.xml is the inner part where you put your own layout (the blank space).
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 activity" then content_main.xml won't be generated and it won't be having floating button, but just simple Activity.
activity_main and content_main are linked to each other.
You can use either both. But to be specific, you should use activity_main.
let me explain this further.
activity_main, this is where the content_main is placed. This is a mother and child case, where activity_main is the mother and content_main is the child.
content_main, this is where you put your controls / content e.g button. This represents as the body of your design.
These are just 2 xml layout files which basically represent 2 different layouts. You should use the file based on the layout you want to use in your android app.
Based on the tutorial it is simple that you should use activity_main.xml as it is the layout for the MainActivity.
You can also see the preview of the layout file in android studio as to how it will look in the app.
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.
I have started Android project.Now(in middle of the project) i got new requirement to add Navigation drawer.is it possible to add now?. I tried to change the main_activity.xml . it's not working.....
Android Studio automatically creates a NavigationDrawer Activity for you. Right-click and highlight the option to create a new activity. This will display the various types of activities you can use. Select NavigationDrawer Activity and the mainActivity, navDrawerFragment, activity_main.xml, and navdrawer.xml files will be created for you.