Browse Source

Custom Renderer Implementation for Android

master
Kaustav Chaudhuri 1 year ago
parent
commit
0dae5b1782
2 changed files with 77 additions and 0 deletions
  1. +32
    -0
      GMCabsDriverAssistantSolution/Platforms/Android/CustomRenderer/NoUnderlineEntryRenderer.cs
  2. +45
    -0
      GMCabsDriverAssistantSolution/Platforms/Android/CustomRenderer/OtpEntryRenderer.cs

+ 32
- 0
GMCabsDriverAssistantSolution/Platforms/Android/CustomRenderer/NoUnderlineEntryRenderer.cs View File

@ -0,0 +1,32 @@
using Android.Content;
using Android.Graphics.Drawables;
using GMCabsDriverAssistantSolution.CustomControls;
using GMCabsDriverAssistantSolution.Platforms.Android.CustomRenderer;
using Microsoft.Maui.Controls.Compatibility;
using Microsoft.Maui.Controls.Compatibility.Platform.Android;
using Microsoft.Maui.Controls.Platform;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
[assembly: ExportRenderer(typeof(NoUnderlineEntry), typeof(NoUnderlineEntryRenderer))]
namespace GMCabsDriverAssistantSolution.Platforms.Android.CustomRenderer
{
public class NoUnderlineEntryRenderer : EntryRenderer
{
public NoUnderlineEntryRenderer(Context context) : base(context)
{
AutoPackage = false;
}
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.Background = new ColorDrawable(global::Android.Graphics.Color.Transparent);
}
}
}
}

+ 45
- 0
GMCabsDriverAssistantSolution/Platforms/Android/CustomRenderer/OtpEntryRenderer.cs View File

@ -0,0 +1,45 @@
using Android.Content;
using Android.Views;
using GMCabsDriverAssistantSolution.CustomControls;
using GMCabsDriverAssistantSolution.Platforms.Android.CustomRenderer;
using Microsoft.Maui.Controls.Compatibility;
using Microsoft.Maui.Controls.Compatibility.Platform.Android;
using Microsoft.Maui.Controls.Platform;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
[assembly: ExportRenderer(typeof(OtpEntry), typeof(OtpEntryRenderer))]
namespace GMCabsDriverAssistantSolution.Platforms.Android.CustomRenderer
{
public class OtpEntryRenderer : EntryRenderer
{
public OtpEntryRenderer(Context context) : base(context)
{
}
public override bool DispatchKeyEvent(KeyEvent e)
{
if (e.Action == KeyEventActions.Down)
{
if (e.KeyCode == Keycode.Del)
{
if (string.IsNullOrWhiteSpace(Control.Text))
{
var entry = (OtpEntry)Element;
entry.OnBackspacePressed();
}
}
}
return base.DispatchKeyEvent(e);
}
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
}
}
}

Loading…
Cancel
Save