I have a Xamarin Forms Shell project with custom fonts added in .NET Standard project (Embedded Ressource) and exported like this :
[assembly: ExportFont("Ubuntu-Regular.ttf", Alias = "UbuntuRegular")]
[assembly: ExportFont("Ubuntu-Bold.ttf", Alias = "UbuntuBold")]
[assembly: ExportFont("Ubuntu-Italic.ttf", Alias = "UbuntuItalic")]
I'm using a TabBar in my shell and want to set font Ubuntu. I'm using custom renderer, for iOS it is eas, i just have to do
var normalTextAttributes = new UITextAttributes();
normalTextAttributes.Font = UIFont.FromName("Ubuntu-Regular", 10.0F);
uiTabBarItem.SetTitleTextAttributes(normalTextAttributes, UIControlState.Normal);
in UpdateLayout method from my IShellTabBarAppearanceTracker inherited class. But how can we access theses fonts in Android, i tried something like
var title = menuItem.TitleFormatted;
var typeface = Typeface.CreateFromAsset(Forms.Context.ApplicationContext.Assets, "Ubuntu-Regular.ttf");
var sb = new SpannableStringBuilder(title);
sb.SetSpan(new CustomTypefaceSpan("", typeface), 0, sb.Length(), SpanTypes.InclusiveInclusive);
menuItem.SetTitle(sb);
this solution is based from this post. But it does not work.
Related
I am currently developing a cross-platform (Windows and Mac) app using Uno and WinUI 3. I need to implement a WebView in my project, but I'm having some trouble.
On Windows I can use the new WebView2 from WinUI without any problem, but being not supported by Uno I can't use it on Mac. On Mac I think I can't even use the WebView1 because it is not supported anymore in WinUI 3 (and so in Uno.WinUI, or am I wrong?).
So I thought to use the Xamarin.Forms WebView on Mac, but I don't know how to implement it. I thought to add a new project to the solution with just the WebView and call it from the Uno.Mac project, but it doesn't work.
May you give me any suggestions?
It is possible to use Uno Platform controls in Xamarin.Forms app (see docs). The other way may also be possible as there was a way to embed a Xamarin.Forms control in a native app, and Uno allows embedding native controls (see docs).
However, a more efficient solution would be to use the built-in WebView control that Uno Platform provides (unless it is missing some functionality you require - in which case please raise an issue on GitHub :-) ).
Alternatively, you could also directly embed the native macOS WKWebView (using the steps linked to above) and work with it directly.
Xamarin.Forms controls cannot be used individually in an Uno app, in the same way those cannot be used in a Xamarin.iOS or Xamarin.Android "classic" app.
You can, however, use the the Xamarin.Forms embedding technique described in this article. The base of the technique is to create a ContentPage, then add it as a native control.
Uno Platform supports adding native controls directly in the Visual Tree by assigning the native view to the Content property of a ContentControl using code-behind.
You can easily add Xamarin content into uno and vice versa.
Just try this :
public partial class XamarinContent : ContentControl
{
View _element;
public View Element
{
get => _element;
set
{
_element = value;
#if __ANDROID__
var renderer = RendererFactory.GetRenderer(value);
this.Content = renderer.View;
this.SizeChanged += (s, a) => {
_element.Layout(new Rect(0, 0, a.NewSize.Width, a.NewSize.Height));
};
#else
var converter = new ViewToRendererConverter();
var frameworkElement = converter.Convert(value, null, null, null);
this.Content = frameworkElement;
// this.SetValue(ContentControl.ContentProperty, frameworkElement) ;
#endif
}
}
}
and to convert from uno into Xamarin forms
[ContentProperty("Element")]
public class UnoContent : Xamarin.Forms.TemplatedView
{
public static readonly BindableProperty ContentProperty
= BindableProperty.Create("Element", typeof(Windows.UI.Xaml.FrameworkElement), typeof(View), null);
public Windows.UI.Xaml.FrameworkElement Element
{
get { return (Windows.UI.Xaml.FrameworkElement)GetValue(ContentProperty); }
set { SetValue(ContentProperty, value); base.ControlTemplate = new Xamarin.Forms.ControlTemplate(() => value.ToView()); }
}
}
Fellow Developers,
I'm developing an app with Xamarin.Forms and I am using the latest version 3.1, which as far as I know it supports Bottom Tabs in Android. This is my code:
XAML:
<?xml version="1.0" encoding="utf-8"?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
android:TabbedPage.ToolbarPlacement="Bottom"
android:TabbedPage.BarItemColor="#666666"
android:TabbedPage.BarSelectedItemColor="Black"
BarBackgroundColor="#2196F3"
BarTextColor="White"></TabbedPage>
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace BottomTabsExample
{
public partial class MainPage : TabbedPage
{
public MainPage()
{
var navigationPage = new NavigationPage(new History());
navigationPage.Icon = "ic_history.png";
navigationPage.Title = "History";
var navigationPage2 = new NavigationPage(new History());
navigationPage2.Icon = "ic_earth.png";
navigationPage2.Title = "Earth";
Children.Add(navigationPage);
Children.Add(navigationPage2);
}
}
}
However, they are always display in the upper part as the following image:
The previous image uses Android Oreo 8.1 (I also tested the version 7.1 and I had the same result). I got partial examples from these blogs:
https://montemagno.com/xamarin-forms-official-bottom-navigation-bottom-tabs-on-android/
https://blog.xamarin.com/xamarin-forms-3-1-improvments/
Also, the version of .NET Standard and Xamarin.Forms:
Have any of you experienced it before? Does anyone know what am I doing wrong? Thanks for your support.
Why the tabs are not in the bottom in Xamarin Forms?
I found that your were missing InitializeComponent() in your MainPage, that's why the issue happens.
The InitializeComponent() method will load the XAML content, when you delete this method, your XAML content will be ignored.
Solution:
Set Bottom Tabs in C# code behind:
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
On<Xamarin.Forms.PlatformConfiguration.Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);
I have an IOS App with a Tabbar and an embedded Xamarin Forms Page with a listview.
This is the code used to embedd it:
contactListViewController = new Business.Views.ContactListView { BindingContext = ViewModel }.CreateViewController();
contactListViewController.WillMoveToParentViewController(this);
View.Add(contactListViewController.View);
AddChildViewController(contactListViewController);
contactListViewController.DidMoveToParentViewController(this);
The page is displayed correctly, but it does have an additional bar on the top.
How can I get rid of that? I tried to set it to hidden on the NavigationController. But it doesn't have one (NavigationController is always null).
How can I remove that bar?
The solution is, to hide the Navigationbar on the mainpage not the new added ViewController:
NavigationController.NavigationBarHidden = true;
// add subview.
activityViewController = new Business.Views.ActivityView { BindingContext = ViewModel }.CreateViewController();
activityViewController.WillMoveToParentViewController(this);
View.Add(activityViewController.View);
AddChildViewController(activityViewController);
activityViewController.DidMoveToParentViewController(this);
I want to create app use master page, The IOS is open but have back icon as
on android there not display the master and detail view.
On rootviewmodel as following:
public RootViewModel(IMvxNavigationService navigationService)
{
_navigationService = navigationService;
ShowInitialMenuCommand = new MvxAsyncCommand(ShowInitialViewModelsAsync);
ShowDetailCommand = new MvxAsyncCommand(ShowDetailViewModelAsync);
ShowInitialMenuCommand.ExecuteAsync();
ShowDetailCommand.ExecuteAsync();
}
I want to know how to create master page use mvvmcross 5.4.
I use JxBrowser 6.2 on Windows.
I try to add a swing component (a drop-down menu) above the browser view.
Even adding this component in the modal_layer, the component appears under the browser.
I use this code :
JButton btn = new JButton("Hello");
btn.setBackground(Color.RED);
btn.setBounds(0, 0, 500, 300);
frame.getLayeredPane().add(btn, JLayeredPane.MODAL_LAYER, 0);
Please try using the following approach:
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
Browser browser = new Browser();
BrowserView view = new BrowserView(browser);
You can find more details about this approach at https://jxbrowser.support.teamdev.com/support/solutions/articles/9000013078-jmenubar