指示表单将其他着色用于Android

指示表单将其他着色用于Android

本文介绍了指示表单将其他着色用于Android Theme.Holo.Light的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我不喜欢Xamarin的Android目标的黑暗主题,因此我在Manifest.xml中使用此方法切换为全光:

Since I don't like the dark theme of Xamarin's Android-target, I switched to holo light using this in Manifest.xml:

虽然按钮和标签显示正确的颜色,但创建菜单的方式却与此不同:

While Button and Label appear correctly colored, menus created like so do not:

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

出现TableView菜单,并带有浅灰色白色文本背景.很难阅读.

The menu TableView appears with white text on light grey background. Very hard to read.

我可以指示Xamarin.Forms始终切换颜色吗?

May I instruct Xamarin.Forms to switch colors consistently?

推荐答案

要在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活动"和瞧"中引用样式.
  1. Created the UI color design I wanted using http://jgilfelt.github.io/android-actionbarstylegenerator/
  2. Downloaded the zip file and copied the resources to your Platform Specific Android Directory in the Relevant Drawable folders.
  3. Renamed the styles_example.xml to Styles.xml in the values folder. Changed the Name to the name of the theme I desired and the android holo theme base parent I wanted to use in my case holo.light, an example of my Styles.xml can be seen below.
  4. Reference the style from My android activity and voila.

Style.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
    {
    }

这篇关于指示表单将其他着色用于Android Theme.Holo.Light的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 00:16