Xamarin.Forms Android Project not showing Resource.Layout folder - android

I have a Xamarin.Forms solution in which inside my Android project I have a custom BroadcastReceiver. Inside this class I'm trying to create a custom notification layout using RemoteViews which was explained to me using this thread.
However I am having problems with the construction of this class using the RemoteViews(Android.Content.Context,Resource.Layout) constructor. Specifically the Resource.Layout portion. When I go into the 'Resources' folder there is only a Drawable folder (even when 'Show All Files' is enabled). Which is interesting considering I can access layouts after typing Resource.Layouts.
Is there a way to get a custom .xml id int (or .axml if that's the case) to be referenced for this strategy inside the Layout 'folder', or any other way Xamarin does instead that I may not have knowledge of?

Essentially all you have to do is add a folder in the Android project named "Layout" under the Resources folder. Then create the .axml file. Then the file can be referenced using Resources.Layout and the id retrieved using the method from this thread.

Related

Generating live resource class like R.java in android

How can I generate a live resource class just like what android generates based on its layout xmls, R.java, based on my customized xml file?
Is there any specific plugin for android studio to actively watch for a particular xml file, namely mylayout.xml, and generate a java class, namely myR.java as I'm writing codes?
EDIT: What I want to do is to create NON-VIEW objects from an xml file which defines objects and their attributes, but not in run-time. My intention is to auto-generate a before-run-time class which contains those objects ids and there would be such methods like getMyObject(int id) which automatically instantiate the object from its relevant class.
Android will automatically add the things from any custom XML layout to the R class. You do not need to do anything special for this, beyond coding your custom layout in line with Android's style and requirements. See Creating Custom Views.

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: activity creates xml files

Is it possible for an activity to create xml files and write inside?, or just modify an existing xml files in the res folder?
i am trying to achieve an activity which the user can design a live wallpaper inside it, than save it into an xml file of sort, or modify an existing one (which could be better), and the wall paper service will read that xml file to apply it to the screen.
It a bad practice to modify your code at runtime, moreover I don't think is even possible. a possible solution is to create a default layout, and then modify it using java methods, in case there are not method you should extend the View class of the object (button,imageview...).the following question might be helpful for y
Android Runtime Layout Tutorial
Perhaps this would help
I haven't worked with XML but I doubt it is not possible.

Android Interface Webview

I want to create an interface for my android project. I have 4 seperate projects which will be used as libraries for the final project, 3 of which contain webviews. On the startup screen I want to have 4 buttons and then maybe use the onClick function to launch the respective app. I am having problems declaring the webview in my xml though. The libraries when imported contain webviews so where should they go in the xml? Also is there a way to start the activity of the project when the button is clicked? Instead of just calling methods from the project?
Thanks
What I do in this case is to extend the Service/Activity class from the other project in the project where I want to use it and then add it to the manifest.
For the layout files I was not able to use them directly in another project. So you could add an abstract Method to your webview activitys like
protected int getLayoutId()
and then copy your XML layout files to the core project where you reference the layouts using that method. Don't know if there is any better way to solve this I wasnt able to find any other solution.

Android - Defining Custom Component Layouts in XML

i'm reading the android developer docs on creating custom components and one thing that's unclear, is whether you can define the layout of your component using xml and then reuse that across class libraries. like, say for instance, i want to create a class library called myComponents, and in there i want to have myTehAwesumsWidget or whatever, and i want the layout to be defined in xml, can i include that xml in the referenced class library?
If you replace "class library" with "Android library project", everything you describe should work just fine. Here is an Android library project that distributes a custom widget (also wrapped in a dialog and custom preference).

Categories

Resources