0

由于我不喜欢 Xamarin 的 Android 目标的深色主题,因此我使用以下代码切换到全息光Manifest.xml

虽然Button 和 Label 显示正确的颜色,但像这样创建的菜单不会:

var navMenu = new TableView {
    Intent = TableIntent.Menu,
    Root = new TableRoot {

菜单 TableView 以浅灰色背景上的白色文本显示。非常难读。

我可以指示 Xamarin.Forms 一致地切换颜色吗?

4

1 回答 1

13

为了在 Xamarin Forms 中实现 Android 特定平台样式,我在项目中执行了以下操作:

  1. 使用http://jgilfelt.github.io/android-actionbarstylegenerator/创建了我想要的 UI 颜色设计
  2. 下载 zip 文件并将资源复制到相关 Drawable 文件夹中的平台特定 Android 目录。
  3. 将 values 文件夹中的 styles_example.xml 重命名为 Styles.xml。将名称更改为我想要的主题的名称和我想在我的案例 holo.light 中使用的 android holo 主题基础父级,我的 Styles.xml 示例如下所示。
  4. 参考我的 android 活动中的样式,瞧。

样式.xml:

 <resources>
  <style name="Theme.Splash"
    parent="android:Theme">
    <item name="android:windowBackground"> 
    </item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsTranslucent">false</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:backgroundDimEnabled">true</item>
  </style>

    <style name="Theme.Main" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarItemBackground">@drawable/selectable_background_example</item>
        <item name="android:popupMenuStyle">@style/PopupMenu.Example</item>
        <item name="android:dropDownListViewStyle">@style/DropDownListView.Example</item>
        <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Example</item>
        <item name="android:actionDropDownStyle">@style/DropDownNav.Example</item>
        <item name="android:actionBarStyle">@style/ActionBar.Solid.Example</item>
        <item name="android:actionModeBackground">@drawable/cab_background_top_example</item>
        <item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_example</item>
        <item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Example</item>
    </style>

    <style name="ActionBar.Solid.Example" parent="@android:style/Widget.Holo.Light.ActionBar.Solid">
        <item name="android:background">@drawable/ab_solid_example</item>
        <item name="android:backgroundStacked">@drawable/ab_stacked_solid_example</item>
        <item name="android:backgroundSplit">@drawable/ab_bottom_solid_example</item>
        <item name="android:progressBarStyle">@style/ProgressBar.Example</item>
    </style>

    <style name="ActionBar.Transparent.Example" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">@drawable/ab_transparent_example</item>
        <item name="android:progressBarStyle">@style/ProgressBar.Example</item>
    </style>

    <style name="PopupMenu.Example" parent="@android:style/Widget.Holo.Light.ListPopupWindow">
        <item name="android:popupBackground">@drawable/menu_dropdown_panel_example</item>   
    </style>

    <style name="DropDownListView.Example" parent="@android:style/Widget.Holo.Light.ListView.DropDown">
        <item name="android:listSelector">@drawable/selectable_background_example</item>
    </style>

    <style name="ActionBarTabStyle.Example" parent="@android:style/Widget.Holo.Light.ActionBar.TabView">
        <item name="android:background">@drawable/tab_indicator_ab_example</item>
    </style>

    <style name="DropDownNav.Example" parent="@android:style/Widget.Holo.Light.Spinner">
        <item name="android:background">@drawable/spinner_background_ab_example</item>
        <item name="android:popupBackground">@drawable/menu_dropdown_panel_example</item>
        <item name="android:dropDownSelector">@drawable/selectable_background_example</item>
    </style>

    <style name="ProgressBar.Example" parent="@android:style/Widget.Holo.Light.ProgressBar.Horizontal">
        <item name="android:progressDrawable">@drawable/progress_horizontal_example</item>
    </style>

    <style name="ActionButton.CloseMode.Example" parent="@android:style/Widget.Holo.Light.ActionButton.CloseMode">
        <item name="android:background">@drawable/btn_cab_done_example</item>
    </style>

  <!-- this style is only referenced in a Light.DarkActionBar based theme -->
    <style name="Theme.Example.Widget" parent="@android:style/Theme.Holo">
    </style>

</resources>

活动代码:

namespace Test.Droid
{
    [Activity(Label = "Test", ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize,Theme = "@style/Theme.Main")]

    public class MainActivity : AndroidActivity
    {
    }
于 2014-08-06T19:25:13.613 回答