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
Related
I want to make something like this in my android app
With 2 or 3 activities or more. I don't want to use visible tabs with names. I just want when i slide through a new activity with its own layout appear, a totally different screen. I've read about viewpager and pageradapter, but i' m a little confused. What do you think is the best way to do it?
This is what you need, just follow this tutorial http://www.androidhive.info/2015/09/android-material-design-working-with-tabs/
You dont even need multiples activities.
You can actually create a swiping activity in android studio.
Goto:
File -> New -> Activity -> Tabbed Activity and choose Navigation Style to be Swipe Views.
Android Studio will do the rest. Then you can change the fragments according to your need.
EDIT:
This is a nice example that demonstrate using Activity with ViewPager.
Android PagerView between Activities
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
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.
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.
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.