我在我的android应用程序中有一个自定义的选项卡栏渲染器,每次我应用它时,选项卡都会消失。此外,当我尝试访问选项卡页中的工具栏时,它总是返回null。但是如果我在我的内容页面中访问它,如下所示
var toolbar =(Android.Support.V7.Widget.Toolbar)MainActivity.RootFindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);它可以工作。我的问题可能是什么?
TabbarDroid:
// Every time applied i lose my tabs
[assembly: ExportRenderer(typeof(BaseTabbedPage), typeof(Aura.SSC.MobileX.Droid.Renderers.TabbedPageRenderer))]
namespace Aura.SSC.MobileX.Droid.Renderers
{
public class TabbedPageRenderer : TabbedRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e)
{
base.OnElementChanged(e);
}
}
}Tabbar XML代码:
<?xml version="1.0" encoding="utf-8" ?>
<views:BaseTabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Aura.SSC.MobileX.Pages.MainPage2"
xmlns:views="clr-namespace:Aura.SSC.MobileX.Views"
xmlns:videos="clr-namespace:Aura.SSC.MobileX.Pages.Videos"
xmlns:account="clr-namespace:Aura.SSC.MobileX.Pages.Account"
xmlns:help="clr-namespace:Aura.SSC.MobileX.Pages.Help">
<TabbedPage.ToolbarItems>
<ToolbarItem Icon="ic_launch.png" Clicked="ToolbarItem_Clicked"/>
</TabbedPage.ToolbarItems>
<TabbedPage.Children>
<views:BaseNavigationPage Title="Videos" Icon="ic_play_button.png">
<x:Arguments>
<videos:VideosMasterPage />
</x:Arguments>
</views:BaseNavigationPage>
<views:BaseNavigationPage Title="Account" Icon="ic_account.png">
<x:Arguments>
<account:AccountsMasterPage />
</x:Arguments>
</views:BaseNavigationPage>
<views:BaseNavigationPage Title="Help" Icon="ic_lifesaver.png">
<x:Arguments>
<help:HowToPage />
</x:Arguments>
</views:BaseNavigationPage>
<views:BaseNavigationPage Title="Upload" Icon="ic_upload_button.png">
<x:Arguments>
<videos:UploadPage />
</x:Arguments>
</views:BaseNavigationPage>
</TabbedPage.Children>
Tabbar.axml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.TabLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:tabIndicatorColor="@android:color/white"
app:tabMaxWidth="0dp"
app:tabGravity="fill"
app:tabMode="fixed" />发布于 2018-03-19 23:23:49
我在我的android应用程序中有一个自定义的选项卡栏渲染器,每次我应用它时,选项卡都会消失。
您可以尝试使用TabbedPageRenderer而不是TabbedRenderer。
例如:
public class MyTabbedPageRenderer : TabbedPageRenderer
{
public MyTabbedPageRenderer(Context context) : base(context)
{
}
}同样,当我试图访问选项卡页中的工具栏时,它总是返回null。
工具栏为空,因为它从未在活动中设置过。您需要先设置它。
var toolbar = (Android.Support.V7.Widget.Toolbar)LayoutInflater.Inflate(Resource.Layout.Toolbar, null);
SetSupportActionBar(toolbar);还需要使用NavigationPage和修改style.xml
MainPage = new NavigationPage(new BaseTabbedPage());style.xml
<!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
<item name="windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="windowActionBar">false</item>https://stackoverflow.com/questions/49323114
复制相似问题