3

First question

My app is only for internal use so I never ever need dark theme support. I use the newest xamarin forms. How to disable dark theme globally in app? It's pretty easy in ios subproject.

Second question

How to change color of border of text entry in light and dark mode? I can change it in subprojects with custom reneders but I need comprehensive solution for shared project.

Cfun
  • 8,442
  • 4
  • 30
  • 62
  • It is not very clear what you are asking.. if you are not setting it up then the style used for your app is independent from dark/light theme. https://devblogs.microsoft.com/xamarin/app-themes-xamarin-forms/ – Cfun Jan 02 '21 at 17:37
  • @NightCity10932 You want to change app theme? If yes, please take a look [Theme a Xamarin.Forms Application](https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/theming/theming) – Cherry Bu - MSFT Jan 04 '21 at 07:17
  • Put this in App.xaml.cs constructor : Xamarin.Forms.Application.Current.UserAppTheme = OSAppTheme.Light; It will keep your app in Light theme. – MilanG Jan 05 '21 at 13:30
  • Possible duplicate: https://stackoverflow.com/q/64755827 – Cfun Jan 05 '21 at 22:09
  • It isn’t duplicate because there is no real answer in your link. Create project with shell or tabbed page in the newest visual studio from template and deploy it to your smartphone. I use Huawei P30 and my app is not theme independent. I don’t want to use appthemebinding. I prefer disable it for real. – NightCity10932 Jan 08 '21 at 12:18
  • @NightCity10932 If you want to disable dark theme, you consider to change theme using resourcedictionary? – Cherry Bu - MSFT Jan 18 '21 at 08:34
  • For Android I used this solution: https://stackoverflow.com/a/68622874/6846888 – Ângelo Polotto Aug 02 '21 at 13:58

3 Answers3

0

You will need to create a new CustomerRenderer, like this one: https://www.youtube.com/watch?v=pWvYNZOQo-A&ab_channel=AyberkZeray

then modify the info.plist with this lines (open the file with a text editor):

<key>UIUserInterfaceStyle</key>
<string>Light</string>
El0din
  • 3,208
  • 3
  • 20
  • 31
0

For customizing for dark mode is not super difficult

In the view use AppThemeBinding like the below, can be applied against different attributes to give different color based off Light or Dark Mode.

BackgroundColor="{AppThemeBinding Light=BlanchedAlmond, Dark=Black}
0

In your MainActivity.cs file, add :

using AndroidX.AppCompat.App;

Then, after the base.onCreate(savedInstanceState) :

AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightNo;
Bibimission
  • 317
  • 5
  • 17