c# - How to enable a Toolbar in Xamarin Forms -
i have simple xamarin project xaml , use material design, seems enable default toolbar doesn't show along mainpage. or need add toobar xaml?
mainpage.xaml :
<contentpage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:material" x:class="material.mainpage"> <label text="welcome xamarin forms!" verticaloptions="center" horizontaloptions="center" /> <toolbaritem name="test" /> </contentpage>
style.xml :
<style name="maintheme" parent="maintheme.base"> </style> <style name="maintheme.base" parent="theme.appcompat.light.darkactionbar"> <item name="windownotitle">true</item> <item name="windowactionbar">false</item> <item name="colorprimary">#2196f3</item> <item name="colorprimarydark">#1976d2</item> <item name="coloraccent">#ff4081</item> <item name="windowactionmodeoverlay">true</item> <item name="android:datepickerdialogtheme">@style/appcompatdialogstyle</item> </style> <style name="appcompatdialogstyle" parent="theme.appcompat.light.dialog"> <item name="coloraccent">#ff4081</item> </style>
toobar.axml :
<android.support.v7.widget.toolbar xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorprimary" android:theme="@style/themeoverlay.appcompat.dark.actionbar" android:popuptheme="@style/themeoverlay.appcompat.light" />
tabbar.axml
<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" android:theme="@style/themeoverlay.appcompat.dark.actionbar" app:tabindicatorcolor="@android:color/white" app:tabgravity="fill" app:tabmode="fixed" />
mainactivity.cs :
[activity(label = "material", icon = "@drawable/icon", theme = "@style/maintheme", 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()); } }
i following this tutorial. thanks!
you should wrap contentpage
in navigationpage
in app.(xaml).cs
.
so when defining mainpage
inside app.(xaml).cs
way:
public app() { initializecomponent(); mainpage = new navigationpage(new mainpage()); }
when navigating further, not have wrap contentpage
in navigationpage
each time, navigation relative.
Comments
Post a Comment