After this try:
https://learn.microsoft.com/en-us/answers/questions/562442/unable-to-use-custom-theme-in-android-xamarinforms.html
And after resolving this error:
https://learn.microsoft.com/en-us/answers/questions/565478/androidviewsinflateexception-binary-xml-file-line.html
I could change the statusBarColor and the navigationBarColor but not the colorPrimary of the action bar.
This is MainActivity.cs:
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.OS;
using Xamarin.Forms.Internals;
namespace Almicantarat.Droid
{
[Activity (Label = "Almicantarat",
Icon = "@drawable/almicantarat_launcher",
MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
//Theme = "@style/MainTheme",
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate (Bundle savedInstanceState)
{
base.OnCreate (savedInstanceState);
Xamarin.Forms.Forms.SetFlags("SwipeView_Experimental");
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
Registrar.Registered.Register(typeof(Xamarin.Forms.CheckBox), typeof(Xamarin.Forms.Platform.Android.CheckBoxRenderer));
global::Xamarin.Forms.Forms.Init (this, savedInstanceState);
Xamarin.FormsMaps.Init(this, savedInstanceState);
LoadApplication(new AlmicantaratXF.Views.App (AlmicantaratXF.Views.FirstPage.HomePage));
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}
This is styles.xml:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="AlmicantaratTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:colorPrimary">#15014E</item>
<item name="android:colorPrimaryDark">#15014E</item>
<item name="android:navigationBarColor">#15014E</item>
<item name="android:statusBarColor">#15014E</item>
<item name="android:colorAccent">#FF4081</item>
<!--<item name="android:windowActionModeOverlay">true</item>-->
</style>
</resources>
This is AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="preferExternal" package="almicantarat.almicantarat" android:versionCode="17" android:versionName="1.3.0">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application android:label="Almicantarat"
android:icon="@drawable/almicantarat_launcher"
android:theme="@style/AlmicantaratTheme">
<meta-data android:name="com.google.android.geo.API_KEY" android:value="***" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<uses-library android:name="org.apache.http.legacy" android:required="false" />
</application>
</manifest>
And this is the result:
The actionBar is black instead of the primaryColor I set (#15014E)