dotnet / dotnet/maui

Can't remove the offset between text and bottom border (underline) for Entry

Open
#36,041 2 comments 1 reaction 0 assignees View on GitHub
area-controls-entry has-workaround partner/syncfusion platform/android s/triaged s/verified t/bug
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 10h
Merged PRs (30d)
297

Description

### Description

After visually removing the `Entry` underline by setting `Background` to `null` and setting `Padding` to `0` on all sides, to achieve the effect I want, there is still **extra space** between the text and underline.

Without underline:

Image

With underline:

Image

This clearly comes from the component itself. I did not find any setting that either adjusts the text position or actually removes the underline from being rendered allowing text to be directly placed on top of underline without that extra space between text and underline.

### Steps to Reproduce

1. Create an empty MAUI project.
2. Add a `ContentPage` using a template, and add an `Entry`:

`MainPage.xaml`

```

```

`MainPage.xaml.cs`

```
namespace YourApp;

public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
}
```

4. Create a `CustomEntryHandler` for said Entry:

```
#if ANDROID

using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;

namespace YourApp;

public class CustomEntryHandler : EntryHandler
{
protected override void ConnectHandler(MauiAppCompatEditText platformView)
{
base.ConnectHandler(platformView);
platformView.SetPadding(0, 0, 0, 0);
platformView.ShowSoftInputOnFocus = false;
if (OperatingSystem.IsAndroidVersionAtLeast(29))
{
// Or darker color if on lighter background
platformView.TextCursorDrawable?.SetTint(Colors.Lavender.ToInt());
}
}
}

#endif
```

5. Wire it up to `Entry` in `MauiProgram.cs`:
```
using Microsoft.Maui;
using Microsoft.Maui.Hosting;

namespace YourApp;

public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();

builder
.UseMauiApp()
.ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler();
});

return builder.Build();
}
}
```
6. Expected behavior: no padding between text and underline.
7. Actual behavior: there is padding between text and underline.

### Link to public reproduction project repository

_No response_

### Version with bug

10.0.70

### Is this a regression from previous behavior?

Not sure, did not test other versions

### Last version that worked well

_No response_

### Affected platforms

Android

### Affected platform versions

Android 16

### Did you find any workaround?

_No response_

### Relevant log output

```shell

```

Contributor guide

Open the contributing guide

Research direction

Start with the Android Entry handler and the CustomEntryHandler shown in the issue, using MainPage.xaml and MauiProgram.cs to reproduce the behavior. Compare the native EditText underline and padding behavior when the handler sets all padding to zero. Done means the Android Entry text sits directly against the underline without the unwanted gap, with coverage for the reported setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, csharp
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.