2016-08-29 7 views
1

Ich habe ein einfaches Xamarin-Projekt mit XAML und ich möchte ein Material Design verwenden, es scheint standardmäßig aktiviert zu sein, aber die Symbolleiste wird nicht zusammen mit der MainPage angezeigt. Oder muss ich eine Toobar vom Xaml hinzufügen?So aktivieren Sie eine Symbolleiste in Xamarin Forms

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 to 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 This Tutorial folgte. Vielen Dank!

Bisher habe ich das jetzt noch ... enter image description here

+0

Als das Tutorial, das ich hier erwähnt habe, ist die Actionbar weg, jetzt ist es AppCompat v7, er hat das Tutorial gemacht und die Toolbar erstellt. –

Antwort

3

Sie wickeln sollten Ihre ContentPage in ein NavigationPage in Ihrem App.(xaml).cs.

also bei der Definition Ihrer MainPage in Ihrem App.(xaml).cs es auf diese Weise tun:

public App() 
{ 
    InitializeComponent(); 
    MainPage = new NavigationPage(new MainPage()); 
} 

Wenn Sie weiter navigieren, würden Sie nicht die ContentPage in einem NavigationPage jedes Mal haben zu wickeln, wie Navigation ist relativ.

+0

danke, es funktioniert! –