I want to implement a custom entry in xamarin, followed some youtube tutorials step by step and it works on them but mine crashes when launching it via a live player.
Here is the code in the shared project
using Xamarin.Forms;
namespace QuickTest.CustomControls
{
public class PlainEntry : Entry
{
}
}
And here is the android specific version
using Android.Content;
using QuickTest.CustomControls;
using QuickTest.Droid.CustomAndroidControls;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(PlainEntry), typeof(PlainEntryAndroid))]
namespace QuickTest.Droid.CustomAndroidControls
{
public class PlainEntryAndroid : EntryRenderer
{
public PlainEntryAndroid() : base(null) { }
public PlainEntryAndroid(Context context) : base(context) { }
}
}
Its a basic implementation i commented out the OnElementChanged function just so i could get it to run first, is there something am doing wrong, any help would be highly appreciated because i have already wasted enough time on this, thanks.
Btw I have also tried it without either of the constructors and it failed.
Xamarin crashes on Android when creating custom renderer. it didn't give out any error, just xamarin player was crashing
Please refer to the documentation: Limitations of Xamarin Live Player
For Xamarin.Forms:
Custom Renderers are not supported.
Effects are not supported.
Custom Controls with Custom Bindable Properties are not supported.
Embedded resources are not supported (ie. embedding images or other resources in a PCL).
Third party MVVM frameworks are not supported (ie. Prism, Mvvm Cross, Mvvm Light, etc.).
That's why the issue happened. So, it is suggested that deploy your project to an android emulator or a real device.
Related
I'm trying to create a react-native apps with three js using expo-gl, expo-three frameworks.
Following is the list of imports..
import { ExpoWebGLRenderingContext, GLView } from 'expo-gl';
import ExpoTHREE, { Renderer, TextureLoader } from 'expo-three';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
import * as React from 'react';
import {
AmbientLight,
HemisphereLight,
BoxBufferGeometry,
Fog,
GridHelper,
Mesh,
MeshStandardMaterial,
PerspectiveCamera,
PointLight,
Scene,
SpotLight,
Camera,
InstancedMesh,
} from 'three';
import OrbitControlsView from 'expo-three-orbit-controls';
Apart from the basic scene, camera and light setup I'm trying to load a glb model using the ExpoTHREE.loadAsync method as below...
const loadGlb = async ()=>{
const obj = await ExpoTHREE.loadAsync(
[require('./assets/suzanne.glb')],
null,
null}).
then((e)=>{
scene.add(e.scene);
e.scene.traverse((f)=>{if(f.isMesh){f.material = new THREE.MeshNormalMaterial();}});
})
.catch((err)=>{console.log(err)});
}
loadGlb();
Using the ref: https://www.npmjs.com/package/expo-three
The model loads when I run the code on the desktop browser but not on my android phone using expo app. Please let me know what am I doing wrong.
You can access the app here https://expo.io/#praful124/expo3
I had the same problem and ended up running into the fact that it does not support textures inside the glb file. But if you find a solution, I will be very happy if you share them.
I'm triyng to show the status bar in an Android phone using Unity. I have try this code:
void Start() {
this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
But an error appear;
Assets/Scenes/Control/control.cs(15,34): error CS0103: The name 'WindowManager' does not exist in the current context
Does I need to call or import another package? Some could help me with this detail. Thanks in advance.
You cannot use Android Java functions directly in Unity. You can only use whats available in Unity C Sharp. Unity doesn’t understand the method. Suggested workaround, use a ‘Slider’ UI element and manipulate it in a custom c sharp script. Complicated workaround create a custom Unity Plugin which calls the native Android method (possible but complex).
How do I implemement MVVMCross in a "Blank Android App"
Is it possible to do this without a Portable Class Library (PCL)?
Do I have to create an App.cs class (The project doesn't come with one included) and is that even possible?
If I do have to then how do I do it?
A good example for startes is the TipCalc-Tutorial which you will find on the official github page (https://github.com/MvvmCross/MvvmCross/wiki), just be careful since most tutorials are for 4.0 so there might some changes. As a example:
When asked to choose platforms, select .NET Framework 4.5, Windows 8,
Windows Phone Silverlight 8, Windows Phone 8.1, Xamarin.Android and
Xamarin.iOS - this will ensure that the PCL is in Profile259.
Is outdated since Silverlight isnt supported anymore from MVVMCross 4.2.2 onwards. So you should use Profile 7 as a Example. More informations for PCL Profiles here: http://danrigby.com/2014/05/14/supported-pcl-profiles-xamarin-for-visual-studio-2/
But yeah you basically should have a Portable Class Library, even if it would work without it. It just gives many advantages without requiring much effort.
And you dont need a "App.cs", but you need a class which inherits from MvxApplication. So it might be easier to stick with that name, since everyone knows then what it is for.
But just check out the tutorials first, everything in there should be explained.
After doing some research I found that you can create an App.cs file (ie a class that extends the Android.App.Application class) in a 'Blank Android App' and hence don't need a PCL to use MVVMCross.
You must ensure that you have an implementation of the public App(IntPtr javaReference, JniHandleOwnership transfer) constructor and some people state that you also need to override the OnCreate method (as i have done).
Also make sure that in your AssemblyInfo.cs file you DONT have a any [Application] lines ie. None of this: [assembly: Application(Debuggable = true)]
See code below.
using Android.App;
using Android.Runtime;
using System;
namespace YOUR.NAMESPACE
{
#if DEBUG
[Application(Debuggable = true)]
#else
[Application(Debuggable = false)]
#endif
public class App : Application
{
public App(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
{
//Do MVVMCross setup Here
//Mvx.RegisterType<ICalculation,Calculation>();
//Mvx.RegisterSingleton<IMvxAppStart>(new MvxAppStart<TipViewModel>());
}
public override void OnCreate()
{
base.OnCreate();
}
}
}
I am trying to render a checkbox in a Xamarin Forms app. There is nothing rendered at runtime, as far as I can tell the renderer is not even getting called.
Does anyone understand what I am missing or doing incorrectly?
Here is my class in Forms:
public class LegalCheckbox : View
{
public LegalCheckbox ()
{
}
}
And my custom renderer class in Droid:
public class CheckBoxRenderer : ViewRenderer<LegalCheckbox, CheckBox>
{
protected override void OnElementChanged (ElementChangedEventArgs<LegalCheckbox> e)
{
base.OnElementChanged (e);
CheckBox control = new Android.Widget.CheckBox(this.Context);
control.Checked = false;
control.Text = "I agree to terms";
control.SetTextColor (Android.Graphics.Color.Rgb (60, 60, 60));
this.SetNativeControl(control);
}
}
Along with the Assembly Directive:
[assembly: ExportRenderer(typeof(demo.LegalCheckbox), typeof(demo.Droid.CheckBoxRenderer))]
Took your code and fired up a new project with it. The code appears to function fine.
Only thin I can think that might be causing you an issue is the location of you assembly attribute. I typically place them just above the namespace declaration in the same file as my renderer.
I threw what I created up on my github maybe you can spot the difference.
https://github.com/DavidStrickland0/Xamarin-Forms-Samples/tree/master/RendererDemo
#Thibault D.
Xlabs isn't a bad project but its basically just all the code the opensource community came up with during the first year or so of Xamarin.Forms life. Its not really "Their Labs projects" and considering how much of it is marked up with Alpha Beta and the number of bugs in their issues page it's probably best not to imply that the Xamarin company has anything to do with it.
I am not sure if that is the issue but it would make more sense to me if your LegalCheckbox would inherit from a InputView rather than View.
Also, even if Xamarin.Forms does not have a Checkbox control you can still have a look at their "Labs" project here:
https://github.com/XLabs/Xamarin-Forms-Labs/wiki/Checkbox-Control
(And I can actually see that they inherit from View...)
We have heard about the possibility to develop in C# on iOS and Android platforms using MonoTouch and Mono for Android
http://xamarin.com/monoforandroid
I have an iOS MonoTouch application that I would like to convert into a Mono for Android version.
How would a simple example, like the piece of code below, translate into Mono for Android?
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace HelloWorld_iPhone
{
public class Application
{
static void Main (string[] args)
{
UIApplication.Main (args, null, "AppDelegate");
}
}
}
There is no use of a static void Main() method in Mono for Android. You basically have a "Main" activity that starts your app.
Here is an example of this:
[Activity (Label="My App", MainLauncher=true)]
public class MyActivity : Activity
{
}
This then generates the appropriate Android manifest file to launch the app. See here.
I would just use File->New Project->Mono for Android App and use what the template generates.