Changing the default dark Android theme to white in Xamarin.Forms? - xamarin

Xamarin.Forms does generate a greyish Android application. I'd like to have a light / white theme in Android (like in the iOS target).
Does a simple way to switch exist?

You can put Theme parameter to ApplicationAttribute of your main activity
like this
[assembly: Application(Icon = "#drawable/Icon", Theme = "#android:style/Theme.Holo.Light")]
Or you can put this string to AndroidManifest.xml
<application android:theme="#android:style/Theme.Holo.Light" />

The answer from ad1Dima got me most of the way there, but I found that in my environment I needed something slightly different. This is what I put in my 'MainActivity.cs' file to change the theme.
[Activity( Theme="#android:style/Theme.Holo.Light",Label = "HealthTechnologies", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : AndroidActivity
Note that the only thing that was new here was the addition of the 'Theme=...'. Everything else was already in the MainActivity.cs file.

open android manifest file
app_name->Properties->AndroidManifest.xml
now add this line inside <manifest>:
<manifest>
...
<application android:theme="#android:style/Theme.DeviceDefault.Light"></application>
...
</manifest>

Related

Android Label/Icon - in AndroidManifest/Build options vs MainActivity

In a Xamarin project, I can set the Android Label and Icon directly via the Build Options UI - which I believe updates the AndroidManifest.xml file
And I can also set it in code like so above the MainActivity class:
[Activity(Label = "MyXamApp", Icon = "#mipmap/ic_launcher", Theme = "#style/MyXamApp.Splash",
MainLauncher = true,
Does one take precedence over the other, do I need both, which is the correct way?
When you set the icon in Option, it will then be used to automatically generate the manifest for you. This is the default value for the Android project.
When you set the Icon, Label in Activity, it would reset the Icon, Label at runtime.
Normally, we would set our own Icon, Label in Activity. If you do not set it again, it would use the Icon, Label value in AndroidManifest file.

Tab Bar doesn't show up on TabbedPage

I'm using Xamarin Forms on Visual Studios 2017. In my PCL, I've created a Tabbed Page and placed children pages inside. However, when I run my code and click on the Tabbed Page, only my first child page (UploadPage) is displayed. I don't see a tab bar at the top or bottom (I'm currently using an Android phone and emulator). Here is the code I have:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Xam1;assembly=Xam1"
x:Class="Xam1.PersonalAccountPage">
<local:UploadPage></local:UploadPage>
<local:MyVideosPage></local:MyVideosPage>
<local:TrainingVideosPage></local:TrainingVideosPage>
</TabbedPage>
and the code behind is:
public partial class PersonalAccountPage : TabbedPage
with the regular constructor.
Is there something I can try to make the TabbedPages work/a reason why they aren't working?
I have met the same issue.I found it's the style theme problem. Here is how I fixed.
In styles.xml file, I changed to
<style name="MainTheme" parent="Theme.AppCompat.Light">
<item name="android:windowActionBar">true</item>
<item name="android:windowNoTitle">false</item>
<item name="android:windowFullscreen">true</item>
</style>
In Android Manifest.xml, I added
<application android:theme = "#style/MainTheme"/>
Place your children page within TabbedPage.Children
<TabbedPage.Children>
<local:UploadPage></local:UploadPage>
<local:MyVideosPage></local:MyVideosPage>
</TabbedPage.Children>
OR do it programtically:
public MyTabbedPage ()
{
InitializeComponent ();
Children.Add(new Page1());
Children.Add(new Page2());
}
You probably have not initialized Page's title.
Do it in constructor like:
public MyPage()
{
InitializeComponent();
Title = "MyPage";
}
or in XAML. It worked for me.
In my case it was similar to the theme stuff mentioned by #jason-ye. In my MainActivity class I was inheriting from global::Xamarin.forms.Platform.Android.FormsApplicationActivity - I switched this to FormsAppCompatActivity and my tabs started appearing again. I had previously needed to switch the inheritance due to a different build error (red herring.. total waste of time) and ended up with a broken tabbed app ever since.

Xamarin The application could not be started

Hi everyones i got a anoying problem:
The application could not be started. Ensure that the application has been installed to the target device and has a launchable activity (MainLauncher = true).
Things i do:
adb uninstall ; nothing happens
try to uninstal app from device: the app dont apeard, even like a fake app whith 0kb
Uninstall Mono Shared Runtine and Api from app
Factory reset
Check in another device
Nothing solve my problem and i dont know who i must do.
Add:
My MainActivity;
[Activity(Label = "AppTecnicos", Icon = "#drawable/icon", Theme = "#style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
I found the error (Finally): my app package name started with uppercase.
AppTecnicos.Droid
I changed it to:
appTecnicos.Droid
The application could not be started. Ensure...has a launchable activity (MainLauncher = true).
One Activity in your application needs to be assigned as the MainLauncher otherwise the Android OS does not know the main entry point to app and what to display.
In Xamarin.Android typically this is done via the ActivityAttribute by assigning MainLauncher = true.
Example:
[Activity(Label = "StackOverflow", MainLauncher = true, Icon = "#mipmap/icon")]
public class MainActivity : AppCompatActivity
{
~~~
}
Ref: ActivityAttribute Class
If you are using visual studio and your aplication is a Xamarin.Forms aplication, this could be happening due to a solution configuration problem.
In that case, try to open the solution properties and within the configuration properties section check that your proyect its checked for deploy.

How to make UWP cordova app icon background to match windows theme

The title says it all.
All images in the platforms/windows/images folder are png files with transparent background, but when I build the app package it becomes gray. Like in the image below.
Is there a way to make my cordova UWP app have a dynamic background that matches the windows theme just like "skype" does.
Files in platforms/windows/images directory
SplashScreen.scale-100.png
SplashScreenPhone.scale-240.png
Square150x150Logo.scale-100.png
Square150x150Logo.scale-240.png
Square30x30Logo.scale-100.png
Square310x310Logo.scale-100.png
Square44x44Logo.scale-100.png
Square44x44Logo.scale-240.png
Square70x70Logo.scale-100.png
Square71x71Logo.scale-100.png
Square71x71Logo.scale-240.png
StoreLogo.scale-100.png
StoreLogo.scale-240.png
Wide310x150Logo.scale-100.png
Wide310x150Logo.scale-240.png
UPDATE:
After reading Dave Smits answer I realized that background color on start menu is defined in cordova generated .appxmanifest file. I edited it manually and changed the element uap:VisualElements attribute BackgroundColor to "transparent" and generated package had a background color of current theme as I asked.
Next step is to change that BackgroundColor property from cordova config.xml, because it will be deleted next time cordova decides to generate a new .appmanifest file
in your manifest you define a color too; make this transparent too
to do directly in cordava add this to your config.xml
<preference name="BackgroundColor" value="0xff0000ff"/>

Error inflating class android.support.v7.widget.Toolbar after updaring to v7.AppCompat Version 23.3 Xamarin Forms 2.2.0.31

I am creating a Xamarin Forms Project and using android.support.v7.widget.Toolbar with FormsAppCompatActivity. The code I'm posting below was working with Xamarin.Android.Support.v7.AppCompat Version: 23.0.1.3
But after I upgraded to 23.3.0 this has started throwing Android.Views.InflateException: Binary XML file line #1: Error inflating class android.support.v7.widget.toolbar exception.
Here is my code for MainActivity
[Activity(Label = "AppMob.Client", Icon = "#drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
FormsAppCompatActivity.ToolbarResource = Resource.Layout.toolbar;
FormsAppCompatActivity.TabLayoutResource = Resource.Layout.tabs;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
Xamarin.FormsMaps.Init(this,bundle);
GoogleAnalyticsHelper.GetGASInstance().Initialize_NativeGAS(Application.Context); //For GA initialization
LoadApplication(new App());
}
}
This is my code for Resource.Layout.toolbar
<?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:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways" />
I have updated Xamarin Forms to 2.2.0.31
Dependencies for this version of Xamarin Forms mention:
Xamarin.Android.Support.v4 (= 23.3.0)
Xamarin.Android.Support.Design (= 23.3.0)
Xamarin.Android.Support.v7.AppCompat (= 23.3.0)
Xamarin.Android.Support.v7.CardView (= 23.3.0)
Xamarin.Android.Support.v7.MediaRouter (= 23.3.0)
it should thus be compatible with 23.3.
May you don't declare theme of layout in your activity.cs
you must add this to youractivity.cs:
Theme = "#style/MyThemesss"
Once I had your problem and I did the below steps to solve it :
Call RequestWindowFeature(WindowFeature.Notiltle) in the first line of OnCreate(Bundle bundle) and above everything else and double check if you did remove the ActionBar .
Clean solution , Remove all support library dependencies , change toolbar Id and restart Visual Studio (or Xamarin Studio) Then re-add support libraries and build solution. (sometimes the cause of error is caching or big piles of other junk files in solution .)
Consider not using "?attr/colorPrimary" instead call the color resource directly.
and after all if you could post your style xml file and main layout ,i would helped more efficiently.
This error is resolved as follows.
You need to update Xamarin Forms for that solution. In the NuGet Package.
The package that says CardView too.
Then you should do clean, rebuild.
This will solve this problem.
I had same problem,
probably you may delete some option in tag like "app:layout_scrollFlags" that not supported in api 21, if all options are ok, delete "?attr" values and put their real value instead.
In my case, I found that I had written android.suport.v7.widget.Toolbar ("suport" with one letter "p" instead of "support")
And it worked immediately when I fixed it.
Cleaning solution and restarting VS helped me.
When debugging Xamarin project, go to Debug->Windows->Exception Settings
Under Common Language Runtime Exceptions uncheck System.Exception

Resources