Splashscreen updates for Android 12 - xamarin

I recently updated my test phone for my app to Android 12. When I go to run my uno-platform app, the splashscreen no longer has my custom image on it. It now has the launcher icon. In doing some reading- this is a change that was done in Android 12. My question is how do I get my splashscreen to once again show my custom image? Will this change also work on Android 11 devices- or is something additional I need to do to handle both cases? Here is my code for my splashscreen- there is one for dark and one for light.
Light Mode Splashscreen(splash_screen.xml in drawable folder):
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<!-- background color -->
<color android:color="#dedcdc"/>
</item>
<item>
<!-- splash image -->
<bitmap
android:src="#drawable/splashscreen"
android:tileMode="disabled"
android:gravity="center" />
</item>
</layer-list>
Dark Mode Splashscreen(splash_screen_night.xml in drawable folder):
<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<!-- background color -->
<color android:color="#888689"/>
</item>
<item>
<!-- splash image -->
<bitmap
android:src="#drawable/splashscreen"
android:tileMode="disabled"
android:gravity="center" />
</item>
</layer-list>
Styles.xml(Light Mode):
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- This removes the ActionBar -->
<item name="windowActionBar">false</item>
<item name="android:windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowNoTitle">true</item>
<!-- Splash Screen -->
<item name="android:windowBackground">#drawable/splash_screen</item>
</style>
</resources>
(In values-night folder for dark mode)Styles.xml:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat">
<!-- This removes the ActionBar -->
<item name="windowActionBar">false</item>
<item name="android:windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowNoTitle">true</item>
<!-- Splash Screen -->
<item name="android:windowBackground">#drawable/splash_screen_night</item>
</style>
</resources>

Starting Android 12, there is a new Splash Screen API that is replacing the current approach to creating splash screens on Android. To use this new API, you will need to migrate to it using steps described in the Android documentation here.
To support both new and older versions of Android, there is a AndroidX Splash Screen API in AndroidX Core library, but that is not bound in Xamarin version of the library at the time of writing (see the issue here on GitHub). Therefore you need to make sure the code for Android 12 support runs only on A12 and newer for now (while older targets can keep using the approach that worked for you until now).

Related

How to use Dark Theme Light Theme in Xamarin Forms?

I am new to Xamarin Forms, I want to use a logo that changes based on the device mode, if it's dark mode, the logo will be white and if it's light mode, the logo will be black. I only found examples on how to do it for colors by adding them to the resource dictionaries(the example is attached below), I tried to do it for the logo, but It didn't work.Can someone share tips or a link of a tutorial that show how to do that?
<ResourceDictionary
x:Class="OpsMobile.Styles.DarkTheme"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Source="Global.xaml">
<!-- Colours -->
<!--<Color x:Key="MainPage">#F58220</Color>-->
</ResourceDictionary>
<ResourceDictionary
x:Class="OpsMobile.Styles.LightTheme"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Source="Global.xaml">
<!-- Colours -->
<!--<Color x:Key="MainPage">#F58220</Color>-->
</ResourceDictionary>

NavigationPage BarBackgroundColor does not work on Xamarin.Android

I have XF app which gives the user an option to change from Light to Dark theme with a button click. I am using the below code:
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Japanese.NavBackgroundRes">
<Style TargetType="NavigationPage">
<Setter Property="BarBackgroundColor" Value="{DynamicResource GridBackgroundColor}"/>
<Setter Property="BarTextColor" Value="{DynamicResource LabelTextColor}" />
</Style>
</ResourceDictionary>
This works perfectly on iOS but not in Android. The BarTextColor property works for both iOS and Android but the BarBackgroundColor only works on iOS. Anyone knows why that is? I am debugging on a physical device if that helps.
There is a concept in Android called the Material design.
Since Xamarin has adopted the Native Java Android Behavior in Xamarin.Android what happens is that the Android application picks the theme in its styles.xml file and uses that style to set the bar background colour.
But of course, there is a workaround. Whatever changes that you need to do on the Android side you will have to update it in the style file for it for eg:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="MyTheme" parent="MyTheme.Base">
</style>
<style name="DrawerArrowStyle" parent="#style/Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#FFFFFF</item>
</style>
<style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#003399</item>
<item name="colorPrimaryDark">#003399</item>
<item name="colorControlHighlight">#003399</item>
<item name="colorAccent">#012348</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
</style>
</resources>
A change in colour here will directly reflect there, for eg ColorPrimary is your toolbar background colour (BarBackgroundColor).
UPDATE
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="#style/ToolbarTheme" >
</android.support.v7.widget.Toolbar>
Then get the toolbar something like this:
var toolbar=yourActivityContext.Window.DecorView.FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
toolbar.SetBackgroundColor(Android.Graphics.Color.Your_Color);
//In case of hex color
toolbar.SetBackgroundColor(Android.Graphics.Color.ParseColor("#ebebeb"));
Use BackgroundColor instead of BarBackgroundColor for android.
use both properties for android and iphone.
<NavigationPage BarBackgroundColor="#F05123" BackgroundColor="#F05123" BarTextColor="White" >

CardView styling not showing on device

I am trying to make a custom style for a cardview on my activity. It works just as I want to in Android Studio. But when I run it on my device - Galaxy S7 Edge android 7.0 - the cardview attributes are not changing. It uses the background from the style of the layout, and the rest of the attributes - elevation, corner radius and card background seem to be ingnored.
I dont get any errors in the log.
The layout uses style="#style/AddItemStyle"
The card uses style="#style/AddItemStyle.CardView"
Thats the card style
<style name="AddItemStyle.CardView" parent="CardView">
<item name="cardBackgroundColor">#color/card_bg</item>
<item name="cardCornerRadius">15dp</item>
<item name="cardElevation">15dp</item>
</style>
Thats the layout style
<style name="AddItemStyle" parent="Theme.AppCompat">
<item name="colorPrimary">#color/mySecondary</item>
<item name="colorAccent">#color/ColorMain</item>
<item name="editTextColor">#color/ColorMain</item>
<item name="android:background">#color/mySecondary</item>
</style>
In android studio
On my phone
For some reason removing android:theme="#style/AddItemStyle" from the activity in manifest fixed the problem. I don't know why but it worked.

How to make activity transparent in Xamarin android

I have refered here. But I just see a black background.
Then I use a Android standard Theme "ThemeTranslucentNoTitleBar". It is still a black background. So how to make a activity completely transparent?
protected override void OnCreate(Bundle bundle)
{
SetTheme(Android.Resource.Style.ThemeTranslucentNoTitleBar);
base.OnCreate(bundle);
SetContentView(Resource.Layout.xxx);
}
After trying lots of times. I find the resolution. You also have to set Android application theme. For exmaple <application android:theme="#android:style/Theme.Translucent" /> If you are using a custom application theme. Do not forget to set android:windowIsTranslucent = true
<style name="CustomTheme"
parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/CustomActionBar</item>
<item name="android:actionMenuTextColor">#color/actionbar_text</item>
<item name="android:windowIsTranslucent">true</item>
</style>

animation effects are not working on locked screen

I am trying to give simple animation effect to dialog. Here I set animation theme to dialog for how it enters and how it exits. This code works properly on unlocked device but on locked device when that dialog comes and I clicked on cancel button, dialog disappear and locked screen is displayed but when i try to unlock screen immediately after clicking button then I see the dialog exits with that animation effect. But this effects goes to background and I want to show that animation effect on locked screen. The same code works on tablet but when i tried to do it on mobile it gives me this abnormal behavior.
this is zoom_out_exit.xml file.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/decelerate_interpolator"
android:zAdjustment="top" >
<translate
android:duration="5000"
android:fromYDelta="0%p"
android:toYDelta="50%p" />
</set>
this is style.xml file
<style name="AnimationTheme" parent="#android:style/Theme.Translucent.NoTitleBar">
<item name="android:windowAnimationStyle">#style/DialogAnimation</item>
</style>
<style name="DialogAnimation" >
<item name="android:windowEnterAnimation">#anim/zoom_in_enter</item>
<item name="android:windowExitAnimation">#anim/zoom_out_exit</item>
</style>
and this theme of animationtheme is set to dialog.
class MyDialog extends Dialog {
MyDialog(Context context) {
super(context, R.style.AnimationTheme);
}
}
can anybody solve my problem ? thanks in advance.

Resources