2017-09-21 4 views
1

Ich kann nicht einmal mit Google finden, wie man das Android-Projekt in Light Theme einstellt.Xamarin Forms setzen Android in Licht

Die Symbolleiste hinter der Schaltfläche "gepunktete" bleibt schwarz, wie bekomme ich sie weiß?

Ich meine die Navigation, die erscheint, wenn Sie die 'gepunktete' Schaltfläche auf der rechten oberen Seite drücken.

enter image description here

<?xml version="1.0" encoding="utf-8" ?> 
<resources> 

    <color name="ListViewSelected">#ff9933</color> 
    <color name="ListViewHighlighted">#E39696</color> 

    <style name="MainTheme" parent="MainTheme.Base"> 
    <item name="android:colorPressedHighlight">@color/ListViewSelected</item> 
    <item name="android:colorLongPressedHighlight">@color/ListViewHighlighted</item> 
    <item name="android:colorFocusedHighlight">@color/ListViewSelected</item> 
    <item name="android:colorActivatedHighlight">@color/ListViewSelected</item> 
    <item name="android:activatedBackgroundIndicator">@color/ListViewSelected</item> 
    </style> 
    <!-- Base theme applied no matter what API --> 
    <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <!--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> 
    <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette --> 
    <!-- colorPrimary is used for the default action bar background --> 
    <item name="colorPrimary">#ff9933</item> 
    <!-- colorPrimaryDark is used for the status bar --> 
    <item name="colorPrimaryDark">#ff9933</item> 
    <!-- colorAccent is used as the default value for colorControlActivated 
     which is used to tint widgets --> 
    <item name="colorAccent">#ff9933</item> 
    <!-- You can also set colorControlNormal, colorControlActivated 
     colorControlHighlight and colorSwitchThumbNormal. --> 
    <item name="windowActionModeOverlay">true</item> 

    <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item> 
    </style> 

    <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog"> 
    <item name="colorAccent">#ff9933</item> 
    </style> 
</resources> 

Antwort

1

Sie müssen in droid/resource/styles.xml ein benutzerdefiniertes Thema erstellen. und wir müssen auch dieses Thema in Ihrem MainActivity anwenden

Thema anwenden auf MainActivity

[Activity(Label = "YourProject.Droid", Icon = "@drawable/icon", Theme = "@style/MyTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] 
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity 

hinzufügen eigenes Thema in Style.XML Datei

<?xml version="1.0" encoding="UTF-8"?> 
<resources> 
    <style name="MyTheme" parent="MyTheme.Base"> 
    </style> 
    <!-- Base theme applied no matter what API --> 
    <style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!--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> 
     <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette--> 
     <!-- colorPrimary is used for the default action bar background --> 
     <item name="colorPrimary">#2196F3</item> 
     <!-- colorPrimaryDark is used for the status bar --> 
     <item name="colorPrimaryDark">#1976D2</item> 
     <!-- colorAccent is used as the default value for colorControlActivated 
      which is used to tint widgets --> 
     <item name="colorAccent">#FF4081</item> 
     <!-- You can also set colorControlNormal, colorControlActivated 
      colorControlHighlight and colorSwitchThumbNormal. --> 
     <item name="windowActionModeOverlay">true</item> 
     <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item> 
     <item name="android:actionBarPopupTheme">@style/CustomActionBarPopupTheme</item> 
    </style> 
    <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog"> 
     <item name="colorAccent">#FF4081</item> 
    </style> 
    <style name="CustomActionBarPopupTheme" parent="android:ThemeOverlay.Material.Light"> 
     <item name="android:colorBackground">#FFFFFF</item> 
     <item name="android:textColor">#000000</item> 
    </style> 
</resources> 
+0

Ich habe das, was Sie gepostet haben, aber der Hintergrund der Symbolleistenliste bleibt dunkel. – user7849697

+0

@ user7849697, Ich habe CustomActionBarPopupTheme für Symbolleisten Thema hinzugefügt. Bitte sehen Sie meine aktualisierten Antworten. und konfigurieren Sie es auch im Hauptstil. –

+0

Ich habe den von Ihnen bereitgestellten Code verwendet, aber er bleibt immer noch dunkel. Sieh dir das Bild an, das ich hochgeladen habe. – user7849697

0

Ich glaube, Sie wäre besser dran, ein wenig von plattformspezifischen Code zu schreiben:

Android

Auf Ihrem MainActivity.cs schreiben Code in dem außer Kraft gesetzt OnCreate-Methodencode sieht folgendermaßen aus:

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()); 
      Window.SetStatusBarColor(Android.Graphics.Color.Argb(255, 0, 0, 0)); //here 
     } 
+0

Ja ich weiß, wie sich ändern die Farbe der Symbolleiste, aber ich spreche über den Symbolleisten-Hintergrund, wenn Sie den "gepunkteten" Knopf drücken! – user7849697