Xamarin.forms: [Material]Unable to override FilledBox style with Outlined

Created on 13 Mar 2019  路  5Comments  路  Source: xamarin/Xamarin.Forms

Description

No matter how I try I cannot change the style of the material Entry from the default Filled to Outlined. Is it really not possible to do so or am I just too unexperienced?

Steps to Reproduce

  1. Add a standard Entry to a Xamarin Forms application
  2. Configure Material Visual library
  3. Try to change the border style of the rendered MaterialFormsTextInputLayout to Outlined

I've tried:

  • overriding the style in my Android styles.xml (XamarinFormsMaterialEntryFilled, this lead to a merged style, I was not aware the style is partial)
  • adding an effect to the entry (effect seems to do nothing at all, I was not able to affect the native control at all)
  • tried to inherit and override the MaterialEntryRenderer but failed immediately as the class is sealed (note: official documentation says I should do this...)
  • adding a new layout file with the same name to my project hoping the renderer will pick it up instead of the built-in (this was a naive idea)

Expected Behavior

Should be able to change the style of the rendered TextInputLayout

Actual Behavior

Cannot change it properly, the most I could achieve is a mixture of the styles looking worse than any of them alone

Basic Information

  • Version with issue: 3.6.0.220655 (NuGet)
  • Last known good version: N/A
  • IDE: VS 2017 Professional (15.9.8)
  • Platform Target Frameworks: .NET Standard 2.0

    • iOS: N/A

    • Android: 9.0 (28)

    • UWP: N/A at the moment

  • Android Support Library Version:
  • Nuget Packages: official Microsoft Xamarin packages + SQLite, Unity, Prism, xunit, Newtonsoft.Json
  • Affected Devices: standard Xamarin.Forms packages plus Xamarin.Forms.Visual.Material
visual bug

All 5 comments

@LoGA80 those are all very useful notes thank you!!

I'm working on this issue now which should give you a lot of good hooks to customize. I'll be sure to address all the points you've made above and give some guidance

https://github.com/xamarin/Xamarin.Forms/issues/5005

tried to inherit and override the MaterialEntryRenderer but failed immediately as the class is sealed

Dangit! I've changed this on an upcoming PR so you should be able to override this in an upcoming release.

Just one update: Effect DOES work, I assigned it accidentally to a hidden control so I had no chance to see it work. But I would prefer using styles than modifying the properties from code.

I might be wrong but I think the styling problem is due that the FilledBox style is explicitly set in the Android TextInputLayout control. If it would not have any style assigned explicitly, it would be possible to assign either FilledBox or Outlined.

I might be wrong but I think the styling problem is due that the FilledBox style is explicitly set in the Android TextInputLayout control. If it would not have any style assigned explicitly, it would be possible to assign either FilledBox or Outlined.

Yea the unfortunate thing about TextInputLayout controls is that they don't make it very easy to style through code

https://issuetracker.google.com/issues/119314741

I tried to use ContextThemeWrappers for it and it kind of worked but it was always a bit off.

The hope with the issue #5005 will be to include some overrides or extension points where you can easily set your own resource id for styling if you need to

We will also provide an out of the box default style for all the material styles that google provides (i.e. outline)

In AndroidX the way these are styled are actually changing to use a property called materialThemeOverlay :-/ soooooo that'll be fun when we have to change it all for that

I'm going to close this for now and let the work be tracked on #5005. Thanks!

Was this page helpful?
0 / 5 - 0 ratings