Is navigation drawer fragments' xml file required in android studio 1.4? - android

I am working on navigation drawer and have Android studio 1.4. I have read that in 1.4 we don't require fragment java files and can use " onNavigationItemSelected" in MainActivity file itself and trigger action on the basis of menu selected. Now my doubt is do i require the corresponding layout files for these menus and same task can be done in the header content xml file created by android studio itself??
Regards,
Navin

Related

Android Studio: are there any methods to navigate to acitivty or view classes which use current xml layout?

In visual studio and .net MVC applications, there are shortcuts to switch between views and controllers (ctrl+M+G) or between designers or form for windows applications (F7 or Shift+F7).
Is there any shortcut to navigate from XML layout editor windows to related activity/view files?
I know there might be more than one usage of an XML file in java files or there might be no usage, but I want to know are there possibly any shortcut keys for navigation?
#VSB in Android Studio, locate the xml file in the project view (In the Left pane). Right click the xml file and click find usage. In Mac the shortcut after selecting the xml is option + F7. Similarly windows shortcut can be found.
To find the xml in the project navigator, just open the xml and then click the icon shown in the attached image. It will directly take you to the xml file in the project navigator.

Android Studio 2.1 layout preview not working from template

I have created a project in Android Studio 2.1 from the Navigation Drawer template. I made no changes to the project files but only one XML layout will show in the Preview: nav_header_main.xml.
The other layouts, activity_main.xml, app_bar_main.xml, content_main.xml all show this:
Shouldn't the built-in templates work out of the box? What setting am I missing?

How to change default template layout files in Android Studio

As you know every time you create new project with some activity, Android Studio generates a default activity_main.xml file with RelativeLayout as the root element and one TextView. But I prefer to use LinearLayout without any nested views. How can I change the way Android Studio generates the default activity_main.xml?
You can do that by editing default template files, which are located in:
...\Android\Android Studio\plugins\android\lib\templates\activities
so for example, default layout file for template of EmptyActivity (note: this one is specific, the other ones have their own res folders) is located in:
...\Android\Android Studio\plugins\android\lib\templates\activities\common\root\res\layout\simple.xml.ftl
by simply replacing RelativeLayout with LinearLayout in your favourite text editor, you get what you want, but instead of that, I recommend you to make your own template, where you can define literally anything, according to your desires.
Edit: For the BlankActivity and a guide how to edit the other templates see this link:
How to change a BlankActivity template default files and a guide how to do it for any others.
in our course, we hacked the default activity. It worked as expected, still a side effect occured while upgrading from Android Studio 3 to 3.1.
The installation wizard detected the default activity template was modified and we had to replace our hacked version with a stock one.
So I suggest creating your own templates in the way Android Studio expects it (ie, through the template options) for a smooth upgrade process.

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 i add Navigationdrawer to an existing Android project?

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.

Categories

Resources