我想在中自定义我的TimePicker。Net Maui在Android上使用Spinner模式(Android中可能的模式(,而不是时钟模式。毛伊岛的汉德勒可能做到这一点吗?我在找类似的东西
#if ANDROID
Microsoft.Maui.Handlers.TimePickerHandler.Mapper.AppendToMapping("MyCustomization", (handler, view) =>
{
??? handler.PlatformView.TimePickerMode ???;
});
#endif
或者我可以以某种方式设计它吗?
TimePicker的默认模式是时钟,该属性可以在android布局xml中设置,也可以在调用构造方法创建时设置。所以你不能用泰拳手柄设置它。
但你可以使用android风格来更改TimePicker的默认模式。
-
在
/Platform/Android/Resource/values
文件夹下创建style.xml:<resources> <style name="Spinner" parent="android:Widget.Material.Light.TimePicker"> <item name="android:timePickerMode">spinner</item> </style> <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar"> <item name="android:timePickerStyle">@style/Spinner</item> </style> <style name="Splash" parent="Theme.SplashScreen"> <item name="windowSplashScreenBackground">@android:color/holo_blue_dark</item> <item name="android:windowSplashScreenIconBackgroundColor">#000000</item> <item name="windowSplashScreenAnimatedIcon">@drawable/logo</item> <item name="windowSplashScreenAnimationDuration">300</item> <item name="postSplashScreenTheme">@style/AppTheme</item> </style> </resources>
-
在AndroidManifest.xml中:
<application android:allowBackup="true" android:theme="@style/Splash" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
-
在你的android部分中添加名为
AndroidX.Core.SplashScreen
的包。 -
删除MainActivity中的
(Theme="@style/Maui.SplashTheme")
,并在其OnCreate方法的第一行中添加以下代码:AndroidX.Core.SplashScreen.SplashScreen.InstallSplashScreen(this);
我做了一个样品来测试。当我在毛伊岛设置项目时,启动屏幕不起作用。飞溅主题。因此,我为应用程序声明另一个主题。但当我使用另一个控件时,启动屏幕不起作用。
因此,您可以尝试使用上面的解决方案,或者只使用以下代码并将AppTheme
设置为MainActivity的主题。然后按照xamarin.android启动屏幕创建一个启动屏幕。
<resources>
<style name="Spinner" parent="android:Widget.Material.Light.TimePicker">
<item name="android:timePickerMode">spinner</item>
</style>
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:timePickerStyle">@style/Spinner</item>
</style>
</resources>