问题
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?
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>
回答1:
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>
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">
回答2:
If you are using AppCompat, try this:
<resources>
<style name="MyTheme" parent="MyTheme.Base">
</style>
<style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
</style>
<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="android:datePickerStyle">@style/style_date_picker</item>
</style>
<style name="style_date_picker" parent="android:Widget.Material.Light.DatePicker">
<item name="android:datePickerMode">spinner</item>
</style>
</resources>
来源:https://stackoverflow.com/questions/38513868/how-to-set-the-android-datepicker-to-spinner-not-calendar-mode-in-xamarin-form