I had creat a gluon project ,then I put some folders and files under assets folder(Android) and I want to read the files in application,now how do I can read the assets folder ? or how do I get the android Context or AssetManager ? under gluon project there is no Activity class or any class extends Activity.I had read all of the gluonMobile API, javaFXports API and developer docs, there is no help!
Dose anyone can help me? I nearly got crazy!
FXActivity which you obtain via FXActivity.getInstance extends Activity, thus you can call fxActivity.getAssets() to get an instance of AssetManager
Related
I have a Xamarin Android library project which is referenced by an Android application project.
The library project has layout files which need to be used by a library project component. The Resource.designer.cs file seems to be generated properly. The layouts are marked as Android Resources. Yet at runtime the resources are not there. Trying to access them just returns 0.
After reading all the SO questions on the topic, I am convinced this should work, but so far it doesn't. Ideas?
Create the Android Class Library.
Create a layout folder in this class library and create a layout in this folder.
Add the code in your xamarin android app.
var btn_Load = FindViewById<Button>(Resource.Id.btn_LoadLibraryLayout);
btn_Load.Click += delegate
{
SetContentView(ClassLibrary1.Resource.Layout.library_layout);
};
I create a button to open the layout in class library.
Result:
You could download from the ClassLibrary_layout folder of GitHub for reference.
https://github.com/WendyZang/Test.git
Updated:
If you want to get the resource identifier, you need the package name of this class library. First, we could not get the package name in AndroidManifest.xml file or properties, because the class library does not have it.
You could get it from the steps below.
Create a activity in class library. And get the package name with the code.
var PackageNname = Application.Context.PackageName;
You could also get the resource identifier in this activity.
var resId2 = Resources.GetIdentifier("library_layout", "layout", PackageNname);
Result:
The paskage name is same to the app1 I provided.
Package Name: com.companyname.app1
You could also use the code directly in app1 activity.
int resId2 = Resources.GetIdentifier("library_layout", "layout", "com.companyname.app1");
The official documentation explains how to migrate an existing Angular Web project to a code-sharing structure.
But I could not find documentation on how to do the other way around. That is, how to migrate an existing NativeScript Mobile project to a code-sharing structure.
Any thoughts on how to convert an existing mobile app project to a web app project?
I have answered this before as well, here are the steps that I followed to do the same.
It is actually very time-saving to use same code base for both Web and mobile. Here are the steps I would suggest based on my experience.
You should be using #angular/cli#6.1.0 or newer. npm i -g #angular/cli
Installl nativescript-schematics. npm i -g #nativescript/schematics
Create a new Project. ng new --collection=#nativescript/schematics my-mobile-app (I did it in this way and then copied over src/app folder here from Mobile app).
Copy the app/src folder from existing project. (You may want to look for source folder in nsconfig.json "appPath": "app")
Find the .ts file where you are using mobile specific components and create a wrapper class for the same. E.g. I was using Fancy Alerts for mobile apps, so I created a wrapper helper class like helper.tns.ts and helper.ts
in helper.ts
public show() {
alert('Javascript+HTML alert') .
}
in helper.tns.ts
public show() {
TNSFancyAlert.showWarning('Warning!', 'Message', `Ok`, 0, 300).then(() => {
resolve('Success');
});
}
Rename all .html to .tns.html and create web specific html files.
Build a web app
ng serve
Build a Mobile app
tns run android --bundle
tns run ios --bundle
P.S. --bundle is the key here to compile mobile specific files only. The HTML code that defines the View of the component should be different between a web and a mobile app.
I am developing UWP app in xamarin. The application works on IOS, Mac , Android, Windows. I have created UWP project in it according to the tutorial given in developer.xamarin.com. But it giving error saying Accessibility.App namespace not found.
Here is my code:
namespace Accessibility.UWP
{
public sealed partial class MainPage
{
public MainPage()
{
this.InitializeComponent();
this.LoadApplication(new Accessibility.App());
}
}
}
According to your description, the app can't see Accessibility.App. As you claim that Android and iOS projects work there are two things that can cause the problem:
you don't have the reference to your Shared/PCL project in your UWP project (most likely).
you have possibly changed the namespace / class name in the Shared/PCL project to something else than Accessibility.App
This is usually caused by missing reference to the shared project or class library where Xamarin.Forms App class resides. From the description this project should be called Accessibility.
Right-click the UWP project select Add, Reference... then in Solution tab select the Accessibility project.
Also it might happen that the UWP project didn't pick up on the reference, so restarting Visual Studio might help as well.
If all fails, you can try to use class name binding with using. On top of the source code file add:
using FormsApp = Accessibility.App;
And then in code use:
this.LoadApplication(new FormsApp());
I am working on Xamarin cross platform project where if I placed the images inside the sub folder it is not loading on the screen.
Please refer my code and folder structure along with properties
Put your Images folder under Assets Folder like this:
Assets/Images/*.png
and if you are using Localizing make like this:
Assets/Images/en/*.png
Assets/Images/another language/*.png
for more information you can check this Working with Images
i hope that answer you question.
I was trying to add Web user control in Class Library in VS2010.
is there a way to do that?
at last I found one way,
just copy the files from other project (website/ web application) and pest them inside Class Library Project.