I'm trying to follow along with the TabbedPageWithNavigationPage sample as shown here: https://github.com/xamarin/xamarin-forms-samples/tree/master/Navigation/TabbedPageWithNavigationPage
However in their sample the Droid project does NOT have a settings.png page see: (https://github.com/xamarin/xamarin-forms-samples/blob/master/Navigation/TabbedPageWithNavigationPage/TabbedPageWithNavigationPage/SettingsPage.xaml)...yet the application gracefully falls back to text only.
In my version (building from scratch) if I do not include the settings.png file, the Droid version crashes with a missing resource error.
I'm sure I'm missing something fundamental...any thoughts on what it might be?
Update MainActivity.CS and App.xaml.cs:
[Activity(Label = "AppZero.Droid", Icon = "@drawable/icon", Theme = "@style/MyTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
}
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new AppZeroPage();
}
protected override void OnStart()
{
// Handle when your app starts
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
}
Update 2 App.xaml
<?xml version="1.0" encoding="utf-8"?>
<Application xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="AppZero.App">
<Application.Resources>
<!-- Application resource dictionary -->
</Application.Resources>
</Application>
Update 3 AppZeroPageCS.cs
using System;
using Xamarin.Forms;
namespace AppZero
{
public class AppZeroPageCS:TabbedPage
{
public AppZeroPageCS()
{
Children.Add(new SettingsPage());
Children.Add(new SettingsPage());
Children.Add(new SettingsPage());
}
}
}
Update 4 SettingsPage.cs
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace AppZero
{
public partial class SettingsPage : ContentPage
{
public SettingsPage()
{
InitializeComponent();
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="AppZero.SettingsPage" Icon="settings.png" Title="Settings">
<ContentPage.Content>
<StackLayout>
<Label Text="Settings go here" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
答案 0 :(得分:0)
您的应用崩溃了,因为您要在SettingsPage.xaml
中分配图标:Icon="settings.png"
。但是,您的Android项目的/Resources/Drawable
文件夹中没有settings.png文件。
有两种方法可以解决这个问题:
Icon="settings.png"
移除SettingsPage.xaml
/Resources/Drawable
文件夹中
Icon="settings.png"
以下是排除SettingsPage.xaml
属性的Icon
的更新版本:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="AppZero.SettingsPage" Title="Settings">
<ContentPage.Content>
<StackLayout>
<Label Text="Settings go here" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
/Resources/Drawable
在/Resources/
内,有多个drawable
个文件夹,每个文件夹都与不同的屏幕分辨率密度相关联。您需要创建多个不同分辨率的png
个文件,并将具有适当分辨率的png
文件添加到相应的文件夹中。
以下是选项卡式页面图标的分辨率:
例如,xhdpi png
的分辨率应为48x48像素。
Xamarin有关于Drawable文件夹的additional documentation。