appcompat_v7 and fragment_main.xml? - android

I've updated my eclipse and ADT Plugin from v22.3 to v22.6 recently and recognised some big changes. Whenever I create a new Android Application Project there appears a new appcompat_v7 library which wasn't present on v22.3 plugin and also a fragment_main.xml file which as I understand is meant to replace activity_main.xml file. Why is that? Why is the activity_main.xml file not preferred for activity layout directly anymore and why appcompat library is now included in every project as a necessity?
Is there a way to bring back the old way of creating projects without losing anything? By the way, I create projects compatible with Android versions from 2.2 to 4.4.

Fragment is useful for navigating through layouts of activity.for example if you have two different layout for portrait and landscape mode then you can simply navigate though the different fragments.
Secondly,
if you can not even get used to it,just remove the default code from activity_main.xml and and cut the fragment_layout.xml and paste it to activity_main.
Then delete the code related to fragment in MainActivity.java.Then delete the fragment_main.xml file.
Hope it will work.It worked for me.

Related

Problem migrating to Jetpack Compose. Trying to run the app from within Android Studio generates a wierd error

I've an application that uses Fragmnent Views with XML resources and I want to migrate it to Compose. Being the app quite big, I decided to temporarily have a mixed environment with Compose working together with the old XML resources, so I created a new Compose fragment and I succeeded to add the standard navigation action to navigate to it. The code builds successfully, but when I try to run the app I get the error of the picture below. It is particularly wierd because this error appears immediately, and not in the build panel, but in a popup dialog. Any hint ?
Ok, the documentation is not very clear, but in the end I found this:
"You can also include a ComposeView directly in a fragment if your full screen is built with Compose, which lets you avoid using an XML layout file entirely."
Being my app a hybrid one with XML navigation graphs, it looks like I need to define an XML resource anyway.
I hoped I cound avoid defining an XML layout, but it seems I need one for a fragment that has an old fashioned Activity as parent.
I'll post an update as soon as I discover something new
UPDATE
Adding an XML layout didn't fix the problem.
In fact the XML layout is not necessary. I don't really understand the cause of that error, but after cleaning a couple of times the project and clearing A.S. cache it disappeared. I succeeded to add a Compose Fragment to an old XML resources style app. The old navigation works without problems. Hope this post will help someone else save the time I have wasted...

Android layout file grayed out

I made an Android layout file recently, and it worked like normal with being able to edit it via the text and design tabs.
Then, I don't know what I did, but the text in the file got grayed out, the android ui icon went away where the files are listed on the left hand side, and I can't call them from inside my Java code. What can I do to convert these files back to Android layout files? Cleaning and rebuilding doesn't work.
You can't put layout files into subfolders, that's why they're not working.
Move them out of the subfolder and into the main folder and they will work again.

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.

Where is the Visual Editor for Eclipse with the ADT plugin

I thought ADT should come with a visual editor for building GUI : Easy way to build Android UI?
However, I just cannot find it. I was wondering where is the Visual Editor for Eclipse with the ADT plugin.
I can run HelloWorld application without problem. However, whenever I click on main.xml at the left navigation tree layout folder, here is what I get. What I wish to get is a WYSIWYG editor.
Select your main.xml file. At the bottom of eclipse you can see a Layout tab, click on it and eclipse will open the android gui editor.
As Paul Kearny previously noted, to resolve issue with seeing "Design" tab instead of "Graphical Layout" follow these 2 steps:
1) Delete project from the left of the screen, without deleting the source files
2) File -> Import -> Existing Projects into Workspace, browse and select your workspace folder and open your project
Graphical Layout problem fixed!
If you want to edit the layout visually, rather than through XML, click on the Layout tab at the bottom left of the main.xml window (in your screenshot, just above Problems).
Also note, there are issues with displaying some of the widgets. For example, the ListView does not render. So, my hint is to change ListView to just a View, then work out the details of the layout so you can get the colors, relative-ness, etc. Then switch it back to ListView. There is one other widget that I cannot recall off the top of my head ...
To resolve issue with seeing "Design" tab instead of "Layout" or "Graphic Layout", I had to:
1. Delete the project from Eclipse without deleting the source
2. Shut down and restart Eclipse
3. Import the project back in
You could probably skip step 2, but I did it just to make sure.
Hope this helps anyone else who has the same issue.
If your view is showing Design|Source for the .xml file right click on the main.xml and select open with - android common XML editor. Simple.
If it is happening to one particular xml, you can delete the file (make sure you copy the content first), create new xml and paste the content again.
I recommend that any serious Android developer stay far, far away from Eclipse/ADT Design View. This is a time-wasting tool that sorely lacks the attention it would need from Google to make it worth serious consideration. It doesn't render the views as a real device would. There is no way to bind dynamic data. Does it work with fragments (I think not)? For it to work properly and have useful features would weigh down Eclipse further and make it unacceptably slow. In my very humble opinion, the entire strategy for ADT's ui-design tools has failed.
Thus, the recommendation is: edit Android XML layout files by hand and use the only reliable testing mechanism you have for layouts: actual devices. You can always fallback on the emulator - but the emulator performs 50x - 100x slower than an actual device. I'm not exaggerating. Pick your poison!
new fix, took me forever to get this fixed, really simple....delete the xml file and undo the deletion (ctrl+z), double click and there you go. Hope this helps someone as it did me. No shut down required.
If you see "Design" tab instead of "Graphical layout", just close the project and open it again.

Unable to open both main.xml files from layout & layout-land at the same time?

While developing for Android, I am unable to open more than one main.xml file in an Eclipse editor at a time. Each time I open one, it simply replaces the editor (tab) of the first main.xml with the new one, instead of opening a new tab - even if the contents of the existing tab were unsaved!
Even stranger, I can open multiple main.xml files from different projects with no problems. This only happens when they're within the same project.
Any idea how to fix or work around this? It's a real time-waster.
(Running Eclipse Classic 3.5.2 64bit w/ADT 0.9.7 on Win7 Home Premium x64)
Edit for clarity:
It's not the same file opened twice. In one project, there is a file called "main.xml" in a directory called "Layout". There is another file also called "main.xml" in a directory called "Layout-Land". These two files cannot be opened at the same time. I'm not sure if this is a problem with Eclipse or with ADT.
More info:
For kicks I created two new files in those same directories (both called "item.txt") and they both opened properly (each in their own tab). I renamed them both to "item.xml" and tried opening them again, and sure enough they fought for the same tab. This leads me to believe ADT is at fault since xml files in these layout directories are opened with ADT's layout tool. I could be wrong though.
Right click on main.mxl and choose 'new editor'- this will create another main.xml which you can replace with the landscape version via a double click.
However, eclipse does this for a reason- so you don't get confused and bork your files up.
I would think you also could edit these files in a text editor to the side with little loss of efficiency.
This is because the two different files represent the same layout just in different configurations. If you want to edit the landscape layout you have to click on the 'Layout' tab at the bottom of the editor and select the 'Config' that you want to edit. Depending on the configuration you select you'll have the layout xml editor fill with the correct contents from each file.

Categories

Resources