Android - Defining Custom Component Layouts in XML - android

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).

Related

Xamarin.Forms Android Project not showing Resource.Layout folder

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.

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.

React Native Custom UI Component using Library

I've developed an android library which exposes some activities, include one named AuthenticiateActivity and also included some helper classes.
I have a second android project that pulls in this library. I am trying create a custom React Native UI component to be able to display the AuthenticateActivity using javascript.
I have followed as best I can the documentation on creating native UI components here, however my use case is slightly different. As I understand, I need to create a ViewManager that extends SimpleViewManager, however, the SimpleViewManager takes a custom view class as a generic parameter. In my case I'm simply trying to display the activity defined in the library, I'm not looking to create a fully custom View implementation.
Any ideas how I can achieve this?
For displaying a completely new Activity you should just use a native module.
There's a good example that shows how to wrap a custom Activity.

Creating customs controls in Android

I want to create my own custom controls in Android application and use them in this way:
In the XML file:
<MyButton .... />
I would like to define MyButton some where in the resources XML
Create your own subclass of View (e.g., com.ofirbit.MyButton) and then reference it in your layouts (e.g., <com.ofirbit.MyButton android:id="..." />). Here is an Android library project and demonstration sub-project showing an implementation of a custom ColorMixer widget and its use in an application. The details of how to implement one of these can be found in some Android books, the Android documentation, and perhaps elsewhere.

Tips on making custom, reuesable components in Android

I want to create a component that will appear as a navigation menu for an Android application. Basically, the custom component is a rectangular "Div" (to use HTML terms) that contains six buttons. Each button provides a link to another part of the application. I want to use this on every "page", so I want to make it easy to maintain.
What is the recommended class to extend for creating custom components like this? (I've seen the "Widget" class, but not sure If this should only be used for widget that appear outside the app (like Google search))
And
Is the process as simple as creating the custom "Widget" class with it's own XML layout and then adding it to each Activity class?
The class to extend is View, the Widget class is for widgets in the homescreen. This is a nice doc to read: Building Custom Components, I suggest to look at the Compound Controls section, that seems suitable for your problem.
Is the process as simple as creating the custom "Widget" class with it's own XML layout and then adding it to each Activity class?
Yes, once you have written your own view, you just have to add it to your layouts in the XML (just like you do with the android views), something like this:
<com.your.package.YourNiceView
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>

Categories

Resources