Customize Android TimePicker to use Spinner in .net Maui - android

I want to customize my TimePicker in .Net Maui to use the Spinner mode on Android(possible modes in android) and not the clock mode. Is this possible with Maui Handlers?
I was looking for something like this
#if ANDROID
Microsoft.Maui.Handlers.TimePickerHandler.Mapper.AppendToMapping("MyCustomization", (handler, view) =>
{
??? handler.PlatformView.TimePickerMode ???;
});
#endif
Or can I style it somehow?

The TimePicker's default mode is clock, and the attribute can just be set in the android layout xml or when it be created by calling the construction method. So you can't set it with the Muai Handler.
But you can use the android style to change the TimePicker's default mode.
Create the style.xml under the /Platform/Android/Resource/values folder:
<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>
In the AndroidManifest.xml:
<application android:allowBackup="true" android:theme="#style/Splash" android:icon="#mipmap/appicon" android:roundIcon="#mipmap/appicon_round" android:supportsRtl="true"></application>
Add the package named AndroidX.Core.SplashScreen in your android part.
Delete the (Theme="#style/Maui.SplashTheme") in the MainActivity and add the following code in the its OnCreate method's first line:
AndroidX.Core.SplashScreen.SplashScreen.InstallSplashScreen(this);
I have done a sample to test. The splash screen doesn't work when I set the item in the Maui.SplashTheme. So I declare another Theme for the application. But when I use the other control, the splash screen doesn't work.
So you can try to use the solution above or Just use the following code and set AppTheme as the MainActivity's theme. And then create a splash screen follwing the xamarin.android splash screen.
<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>

Related

How do I change the theme of my app in android studio?

I change the theme from the design section from the dropdown menu like material dark, holo, etc. But when I run the app on the device the app doesn't show any changes, hence I understood the code does not change so what is the code I need to write in style section to change the theme?
AndroidStudio only shows how it will look if you will apply that theme in your app programmatically by yourself.
In res/values/styles.xml you can add following code to change theme:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="android:colorPrimary">#color/colorPrimary</item>
<item name="android:colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="android:colorAccent">#color/colorAccent</item>
<item name="android:statusBarColor">#color/colorPrimaryDark</item>
<item name="android:colorControlActivated">#color/colorPrimaryDark</item>
<item name="android:colorControlHighlight">#color/colorPrimary</item>
<item name="android:colorControlNormal">#color/colorPrimary</item>
<item name="android:windowBackground">#color/colorBackground</item>
</style>
</resources>
you can change theme by modifying parent attribute
You should edit the application manifest and add
android:theme attribute to either application or activity tag with the theme you want.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
if(mode.equals("dark")){
setTheme(android.R.style.DarkTheme);
}else if(mode.equals("light")){
setTheme(android.R.style.LightTheme);
}else{
setTheme(android.R.style.AppTheme);
}
}

Changing theme of fabric digit screen

I have integrated fabric digits in my app and trying to change its theme.
I try using below code but i don't see any change in theme.What am i missing or doing wrong?
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:digits">#style/CustomDigitsTheme</item>
</style>
<style name="CustomDigitsTheme" parent="android:Theme.Material.Light" tools:targetApi="lollipop">
<item name="android:textColorPrimary">#color/white</item>
<item name="android:textColorSecondary">#android:color/darker_gray</item>
<item name="android:windowBackground">#color/blue</item>
<item name="android:textColorLink">#ff398622</item>
<item name="android:colorAccent">#ff398622</item>
</style
You need to add theme to your authButton, if you're using it, or directly to builder, if you're creating it manually.
You can find sample code in official docs.
For example:
//Example of setting theme with button
digitsAuthButton.setAuthTheme(android.R.style.Theme_Material);
or
//Example of setting theme manually with builder
new Digits.Builder().withTheme(themeId).build();`enter code here`
works as charm :)

Android custom theme

Hello I'm making a custom theme for my app. I want to have a custom ActionBar and background for the rest of the app (below the ActionBar). I'm wondering how to do the background. Right now I have:
<style name="MyTheme" parent="android:Theme.Holo">
<item name="android:actionBarStyle">#style/dActionBar</item>
</style>
<style name="dActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#4C721D</item>
<item name="android:textColor">#FFFFFF</item>
</style>
Would I just have to do <item name-"android:background"></item> in MyTheme or would I have to create another style? After I create this do I need to put it in the res/styles folder? Also what are the API restrictions on this, if any?
Don't forget to apply your theme to your application in your AndroidManifest.xml.
<application android:theme="#style/CustomActivityTheme" ... />
You can find all the information about styling the Actionbar here.
To style your ActionBar with a nice Holo-look, try this website
Hope this helps!
Try to use below code in your Style.xml file
<resources>
<style name="Theme.Sample" parent="Theme.AppCompat">
<item name="android:colorBackground">#color/primary_material_dark</item>
<item name="actionBarTheme">#color/colorGray</item>
</style>
</resources>
Just need to use android:colorBackground as a name of item to define the background color like as below:
<item name="android:colorBackground">#color/primary_material_dark</item>
Hope you get your answer,Thanks.

Set custom theme in Android List Preference

In my Android app, I am using various custom themes in different activities, all of which work fine. All these themes use the same custom styles for buttons, edit controls etc.
My preferences use standard Preference activities, which I define in XML and style via the manifest.
However, when I have a preference that causes an alert dialog to get launched, for example a ListPreference, the dialog uses the standard buttons. It does seem to use my custom EditText style in the EditTextPreference... but not my background or text colour.
Anyone have any idea why this is happening ?
Some of the code:
Styles:
<style name="Theme.Prefs" parent="#android:style/Theme.Holo.Light">
<item name="android:windowBackground">#drawable/background</item>
<item name="android:buttonStyle">#style/CustomButtonStyle</item>
<item name="android:editTextStyle">#style/CustomEditTextStyle</item>
</style>
<style name="CustomButtonStyle" parent="#android:style/Widget.Holo.Button">
<item name="android:background">#drawable/custom_button</item>
<item name="android:textSize">#dimen/dialog_text_size_normal</item>
<item name="android:textColor">#color/dialog_control_colour</item>
</style>
<style name="CustomEditTextStyle" parent="#android:style/Widget.Holo.EditText">
<item name="android:background">#drawable/custom_textfield</item>
<item name="android:textColor">#color/dialog_control_colour</item>
<item name="android:textSize">#dimen/dialog_text_size_normal</item>
</style>
And in the manifest:
<activity
android:name="com.breadbun.prefs.MainPreferencesActivity"
android:theme="#style/Theme.Prefs"
android:screenOrientation="portrait">
</activity>
To customize the alertDialog you need to add the second row to your main theme, and then customize the DialogStyle the way you want it.
<style name="AppTheme" parent="android:Theme.Material">
<item name="android:alertDialogTheme">#style/DialogStyle</item>
</style>
<style name="DialogStyle" parent="android:Theme.Material.Dialog.Alert">
</style>

Custom theme and sherlockActionBar

I am doing a personal theme to use holo widget in 2.3 android.
I did this:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppThemes" parent="#style/Theme.Sherlock">
<item name="android:editTextStyle">#style/EditTextAppTheme</item>
<item name="android:checkboxStyle">#style/CheckBoxAppTheme</item>
<item name="android:radioButtonStyle">#style/RadioButtonAppTheme</item>
<item name="android:buttonStyle">#style/ButtonAppTheme</item>
<item name="android:imageButtonStyle">#style/ImageButtonAppTheme</item>
<item name="android:spinnerStyle">#style/SpinnerAppTheme</item>
<item name="android:dropDownSpinnerStyle">#style/SpinnerAppTheme.DropDown</item>
<item name="android:spinnerDropDownItemStyle">#style/SpinnerDropDownItemAppTheme</item>
</style>
</resources>
the problem is that widgets don't take the correct style but take the default style. I tried to force assign the #style/EditTextAppTheme at an edittext and it worked.. so the problem is that the theme don't apply.
any idea?
update: the theme apply and work good..the solo problem is some edittext inside a dialog that show with the standard theme
To get the holo theme style in an App for API 10 and below, you can use HoloEverywhere. It's well integrated with ActionBarSherlock. ActionBarSherlock is included as a subproject. https://github.com/ChristopheVersieux/HoloEverywhere
If you want to use a customized Theme you have to set these style attributes in your Application theme. Then apply this theme to the whole App or to a single Activity by defining it in the manifest or setting it programmaticaly in the onCreate() method.
For example(for ABS):
<style name="Theme.myStyle" parent="Theme.Sherlock">
<item name="android:editTextStyle">#style/EditTextAppTheme</item>
<item name="android:checkboxStyle">#style/CheckBoxAppTheme</item>
<item name="android:radioButtonStyle">#style/RadioButtonAppTheme</item>
<item name="android:buttonStyle">#style/ButtonAppTheme</item>
<item name="android:imageButtonStyle">#style/ImageButtonAppTheme</item>
<item name="android:spinnerStyle">#style/SpinnerAppTheme</item>
<item name="android:dropDownSpinnerStyle">#style/SpinnerAppTheme.DropDown</item>
<item name="android:spinnerDropDownItemStyle">#style/SpinnerDropDownItemAppTheme</item>
</style>
And then set this theme to your Application or your Activity in the Manifest with:
android:theme="#style/Theme.myStyle"
or programmatically:
setTheme(R.style.Theme.myStyle);

Categories

Resources