Can i add Navigationdrawer to an existing Android project? - android

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.

Related

How to prevent folders from folding in project structure when creating a new activity?

I have a project structure in my project in Android Studio, it is always unfold, so I can see all my layouts in folders. When I create a new activity folders in project structure fold and I have to always search my layouts everytime when I create a new activity.
How can I make folders prevent from folding when I create any activity or a fragment?
I think you talking about Docked Mode. Please do as follows :

How to make my own template activity like the one prebuild in android studio?

How an I make my own template activity like those prebuid in Android studio…and add my own on that Android activity creation page?
I have choosen navigation drawer activity..
For my project I have edited the fab button etc...
But the problem is that I want 200 same layout activities with my options
Is there anyway I can load my own in the add activity option
Or
I have to edit the same for 200 times. ?
Thanks in advance....
An Android Library will do what you want.
Inside Android Studio go to File > New > New Module > Android Library and follow the prompts in the Wizard.
If you need to do more than the basics with it, I suggest this tutorial which goes more in depth.

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.

android studio doesn't create navigation drawer activity

I just want to create a navigation drawer activity. When I Right click on app > new > activity > navigation drawer activity, nothing happens! it just creates a xml file in menu directory. i tried deleting android studio and user preferences files and reinstalling it, but still having the same problem. any suggestions?
First of all , you should create a new activity called navigation drawer activity , you just need to follow these steps : file > new > activity > navigation drawer activity . Then you can modify the xml content and create a navigation drawer like you want .
first create a new project with navigation drawer.
file > new project>navigation drawer activity. and then add content to the template
Make sure all navigation drawer activity files are safely deleted. This means all resource xml files. Also check whether the activity is created in AndroidManifest.xml, if it is remove the said activity.
After deleting all the xml and java files related to navigation drawer you even need to Delete these lines:
"implementation 'androidx.navigation:navigation-fragment:2.3.2'
implementation 'androidx.navigation:navigation-ui:2.3.2'"
in you app.gradle module,then try creating a navigation drawer activity named MainActivity2.
May be the android studio version you are using has problems. I think you are using android studio canary version. Try using stable version. If you are already using stable version then clear data and all the details and start project again.
Make sure that you have deleted all the files related to your previous navigation drawer activity. !!
And also remove the dependencies that were added during your first import.

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.

Categories

Resources