如何在 Xamarin Forms 中将 android datepicker 设置为微调器(不是日历)模式? [英] How to set the android datepicker to spinner (not calendar) mode in Xamarin Forms?

查看:34
本文介绍了如何在 Xamarin Forms 中将 android datepicker 设置为微调器(不是日历)模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Android 设备上的 Xamarin Forms 中选择日期选择器控件时,将显示日期选择器的日历模式视图.如何更改它以显示微调模式?

When selecting the datepicker control in Xamarin Forms on an android device the Calendar Mode view of the datepicker is shown. How can I change it to show the Spinner Mode?

我发现的唯一示例是更新我的styles.xml

The only sample I found was to update my styles.xml

这是我所拥有的,但不起作用

Here is what I have, which is not working

<resources>
    <style name="MyTheme.Base"
    parent="@android:style/Theme.Holo.Light.DarkActionBar">
    </style>

    <style name="MyTheme" parent="MyTheme.Base">
        <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
        <item name="android:dialogTheme">@style/MyDialogTheme</item>
        <item name="android:datePickerStyle">@style/MyDatePicker</item>
    </style>

    <style name="MyTheme.ActionBarStyle"
    parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
        <item name="android:background">@color/material_blue_500</item>
    </style>

    <style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
        <item name="android:textColor">@android:color/white</item>
    </style>

    <style name="MyDialogTheme" parent="android:Theme.Material.Dialog">
        <item name="android:datePickerStyle">@style/MyDatePicker</item>
    </style>

    <style name="MyDatePicker" parent="android:Widget.Material.DatePicker">
        <item name="android:datePickerMode">spinner</item>
    </style>
</resources>

推荐答案

这是对我有用的 Resources/values/styles.xml

Here is the Resources/values/styles.xml that worked for me

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

    <style name="MyTheme.Base" parent="@android:style/Theme.Holo.Light.DarkActionBar">

        <item name="android:dialogTheme">@style/MyDialogTheme</item> 
    </style>

    <style name="MyTheme" parent="MyTheme.Base">
        <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
        <item name="android:dialogTheme">@style/MyDialogTheme</item> 
    </style>

    <style name="MyDialogTheme" parent="android:Theme.Material.Dialog">
        <item name="android:datePickerStyle">@style/MyDatePicker</item>
    </style>

    <style name="MyDatePicker" parent="android:Widget.Material.DatePicker">
        <item name="android:datePickerMode">spinner</item>
    </style>
    <style name="cust_tabViewStyle">
        <item name="android:textColor">@color/material_blue_500</item> 
    </style>

</resources>

然后在Properties/AndroidManifest.xml中将应用程序节点修改成这个来设置主题

Then set the theme in the Properties/AndroidManifest.xml by modifying the application node to this

<application android:label="MyApp" android:icon="@drawable/Icon" android:theme="@style/MyTheme">

这篇关于如何在 Xamarin Forms 中将 android datepicker 设置为微调器(不是日历)模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆