I have the following class in my Droid-Project:
using MyProject.Droid;
using Xamarin.Forms.Platform.Android;
[assembly: Xamarin.Forms.ExportRenderer(typeof(Android.Widget.Button), typeof(ArrowButtonRenderer))]
namespace MyProject.Droid
{
public class ArrowButtonRenderer : Xamarin.Forms.Platform.Android.ButtonRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e)
{
base.OnElementChanged(e);
var btn = this.Control as Android.Widget.Button;
btn.SetBackgroundColor(global::Android.Graphics.Color.Green);
}
}
}
I know, you dont need a custom renderer for changing a button's color, but I just wanna try things out :)
Cheers!
Edit: Here's the code about how I add the button's to the UI:
MyStackLayout.Children.Add(new Button
{
Text = "My Button Text"
});
And some buttons through xaml:
<Button x:Name="btnIdk" Text="something" />
After an extensive chat and looking at your sources I've seen that the PCL has version 2.3.1.114 of Xamarin.Forms installed.
Your Droid project has version 1.5.x installed, so it's much older!
Now the next part will be tricky, you need to update your Xamarin.Forms package for Android. But if you update the Xamarin.Android.Support.* packages first, you'll get an error saying that your can't update Xamarin.Forms because no matching version of Forms is found.
Because Xamarin.Forms for Android depends heavily on the support packages they are linked to a specific version, but they're not always in sync. As of right now the Xamarin.Forms version (2.3.2.127) seems to miss the corresponding Android support packages. So don't upgrade to that, upgrade to the same version as your PCL which is 2.3.1.114. Then the Android packages will be updated to 23.3.0 and everything will work nicely.
Related
Any method in xamarin forms equivalent to shouldoverride method of android?
I am looking for a method that I can call when a button is clicked on webview. this is the android sample code that is working.
webView.Settings.JavaScriptEnabled = true;
webView.SetWebViewClient(new HybridWebViewClient(this));
webView.Settings.DomStorageEnabled = true;
on HybridWebViewClient class
public override bool ShouldOverrideUrlLoading(WebView view, string url)
{
}
Xamarin.Forms is a platform that integrates Android and iOS and Windows. For platform-specific features, you can use Custom renderer to call code on Android platform.
For details you can refer to: What is Xamarin.Forms and Custom renderer.
Using the OnPageStarted method, the OnPageFinished method, and the OnReceivedError method is also a good choice.
Details can be found in the answer at this link:Xamarin.Forms ShouldOverrideUrlLoading Trigger
I'm trying to override the NavigationView behavior:
public partial class CustomizableNavigationView : NavigationView
{
public CustomizableNavigationView()
{
// This gets called
}
protected override void OnApplyTemplate()
{
// This doesn't
}
}
It works on UWP, but not on Android. On Android, it doesn't call OnApplyTemplate and the screen remains blank, there's not content. Questions:
Why doesn't OnApplyTemplate get called on Android? I see that here: https://platform.uno/docs/articles/implemented/windows-ui-xaml-frameworkelement.html it says OnApplyTemplate() is on all platforms
There's no error or anything displayed in the Output panne in VS while running with debugger. Should there be any in this case? Do I need to enable something to log errors?
I noticed that if I don't use partial it gaves me error saying partial is required. This is required only on Android, why is that? A more in-depth explanation would help a lot to understand how things work.
Once I figure out why OnApplyTemplate is not called, I want to do this:
base.OnApplyTemplate();
var settingsItem = (NavigationViewItem)GetTemplateChild("SettingsNavPaneItem");
settingsItem.Content = "Custom text";
My hunch is this won't work on Android. Am I correct? :)
Jerome's answer explains why OnApplyTemplate() was not getting called, to address your other questions:
You can configure logging filters for Uno, this is normally defined in App.xaml.cs. Warnings should be logged by default.
The partial is required because Uno does some code-gen behind the scenes to create plumbing methods used by the Xamarin runtime. Specifically because the control is ultimately inheriting from ViewGroup on Android, it's a native object, and requires special constructors that are used only by Xamarin's interop layer. There's some documentation in progress on this.
Try it and see. :) GetTemplateChild() is supported, and setting ContentControl.Content in this way is supported, so I would expect it to work.
At current version (1.45 and below), the application of styles is behaving differently from UWP. We're keeping track of this in this issue.
The gist of the issue is that Uno resolves the style using the current type and not DefaultStyleKey, and cannot find an implicit style for CustomizableNavigationView.
A workaround for this is to either create a named style from the default NavigationView style, or create an implicit style that uses CustomizableNavigationView as the TargetType instead of NavigationView.
I have an Xamarin Application together with MvvmCross 5.7 and wanted to moved it completly to Xamarin Forms. It builds and starts as expected, but the first page isn't loaded.
I created the projects based this template: https://github.com/martijn00/MvxForms
Also I created a test project to see if something is wrong with my existing project: https://github.com/NPadrutt/XFTestProject
Can anyone point out what I am missing?
Either add a SplashScreen Activity who inherits from MvxSplashScreenActivity and with the method override:
protected override void TriggerFirstNavigate()
{
StartActivity(typeof(MainActivity));
base.TriggerFirstNavigate();
}
Or add these lines to the OnCreate Method in the MainActivity:
var startup = Mvx.Resolve<IMvxAppStart>();
startup.Start();
InitializeForms(bundle);
You don't neet to call startup.Start() in your MainActivity nor you need to init xamarin forms. It's done for you now (check RunAppStart method in mvvmcross sources for MvxFormsAppCompatActivity class).
From a quick glimpse at your GitHub repo, it looks like you're not decorating your view (i.e. WelcomView) with [MvxContentPagePresentation()] attribute (e.g. example from MvvmCross Playground). Add it in your WelcomeView.xaml.cs file and check if that helped
If it's a fresh project, you might want to consider using latest version of MvvmCross (v6). There's an awesome step by step guide to setup Xamarin.Forms with it by Nick Randolph
I'm using Tray Notifications to let the user know about some pending actions. It works fine but would love to be able to click on it and do what I need it to do like showing the correct screen, etc. Sadly I'm unable to find some click listener like other components.
Am I'm missing something?
As far as I know that's not possible with the default notification in either Vaadin 7 or 8.
If you're using Vaadin 7, you can either fake it using a non-modal window (or something similar), or use the fancy-layouts add-on (also compatible with 8) that offers a FancyNotifications component (online demo and source). It's not exactly the same thing but it may provide what you need. Also be careful to select the v7 version and to add the suggested maven repo.
Basic usage:
public class MyUi extends UI {
#Override
protected void init(VaadinRequest request) {
FancyNotifications fancyNotifications = new FancyNotifications();
fancyNotifications.setPosition(FancyNotificationsState.Position.BOTTOM_RIGHT);
Button button = new Button("Show notification", buttonClickEvent -> {
FancyNotification fancyNotification = new FancyNotification(null, "Meh", "Click me to navigate to GITHUB");
fancyNotification.getTitleLabel().setContentMode(ContentMode.HTML);
fancyNotification.getDescriptionLabel().setContentMode(ContentMode.HTML);
fancyNotification.addLayoutClickListener(notificationClickEvent -> Page.getCurrent().setLocation("https://github.com/alump/FancyLayouts"));
fancyNotifications.showNotification(fancyNotification);
});
VerticalLayout content = new VerticalLayout();
content.setSizeFull();
setContent(content);
content.addComponents(button, fancyNotifications);
content.setComponentAlignment(button, Alignment.MIDDLE_CENTER);
}
}
Result:
If you're using 8, there's the notify add-on (online demo and github page) which supports click-listeners. Please be aware that this add-on currently supports Vaadin 8 and works with browsers that support the Notification API:
Development is mainly done on Chrome. Also Firefox is tested and mainly works as planned. Other browsers are still not tested. IE11 and Edge does not support Notification API as far as I know. Anyway add-on can use used only to show notifications on browsers that do support Notification APIs.
From the github demo:
private void showWithClickHandling() {
Notify.show(new NotifyItem()
.setTitle("Notification can be also clicked")
.setBody("Click here to navigate to project's GitHub page")
.setIcon(new ThemeResource("images/github.png"))
.setClickListener(e -> {
Page.getCurrent().setLocation(GITHUB_URL);
}));
}
... which will look like:
I don't find any solution or explaination to use the BackButton hardware (Android & WinPhone 8.1) from MyPage, defined in the PCL part.
Is it possible to handle that button from a Portable Class Library?
Thank
Yes it is. You can ovveride default behaviour for back button in pcl. For example if you want to deactivate it, you can use in the page you want:
protected override bool OnBackButtonPressed()
{
return true;
}