简体   繁体   English

Xamarin.Forms 中 TabbedPage 上的 Android.Views.InflateException

[英]Android.Views.InflateException on TabbedPage in Xamarin.Forms

Error: Android.Views.InflateException: 'Binary XML file line #1: Binary XML file line #1: Error inflating class android.support.design.widget.TabLayout' Error: Android.Views.InflateException: 'Binary XML file line #1: Binary XML file line #1: Error inflating class android.support.design.widget.TabLayout'

I have added new TabbedPage and then in AppShell.xaml我添加了新的 TabbedPage,然后在AppShell.xaml

<ShellContent Title="About" Route="AboutTabbedPage" ContentTemplate="{DataTemplate local:AboutTabbedPage}"  />

but when I tap on "About" in emulator it throws error :但是当我在模拟器中点击“关于”时,它会抛出错误

Android.Views.InflateException: 'Binary XML file line #1: Binary XML file line #1: Error inflating class android.support.design.widget.TabLayout'

The error is thrown on any new TabbedPage.在任何新的 TabbedPage 上都会引发该错误。

the content of TabbedPage is as follows TabbedPage的内容如下

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            x:Class="myapp.Views.AboutTabbedPage"
            Title="{Binding Title}"
             xmlns:vm="clr-namespace:myapp.ViewModels"
            
            >
  <!--Pages can be added as references or inline-->

    <ContentPage Title="Tab 2">
        <StackLayout>
            <Label Text="Green"  HorizontalTextAlignment="Center" HorizontalOptions="FillAndExpand" Margin="5" />
            <BoxView Color="Green" VerticalOptions="FillAndExpand" />
        </StackLayout>
    </ContentPage>
</TabbedPage>

styles.xml in android project is as follows: android项目中的styles.xml如下:

 <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
  </style>

I had to change TabLayout in...Android\Resources\layout\Tabber.xml project from android.support.design.widget.TabLayout To com.google.android.material.tabs.TabLayout then it started working as expected. I had to change TabLayout in...Android\Resources\layout\Tabber.xml project from android.support.design.widget.TabLayout To com.google.android.material.tabs.TabLayout then it started working as expected.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM