You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在MAUI中创建无下划线的Entry输入控件?

如何在MAUI中创建无下划线的Entry输入控件?

方法一:直接设置UnderlineColor属性(最简单)

MAUI的Entry控件自带UnderlineColor属性,将其设置为透明色即可移除默认下划线,无需额外平台定制代码,跨平台通用:

<Entry Placeholder="请输入您的姓名" UnderlineColor="Transparent" />

方法二:使用自定义Handler(高级定制场景)

如果需要更灵活的平台原生属性调整,可通过自定义EntryHandler实现,以Android平台为例:

  1. 创建自定义Handler类:
using Microsoft.Maui.Handlers;
#if ANDROID
using Android.Widget;
#endif

namespace YourAppNamespace;

public class CustomEntryHandler : EntryHandler
{
    protected override void ConnectHandler(EditText platformView)
    {
        base.ConnectHandler(platformView);
        // 移除Android原生EditText的下划线背景
        platformView.Background = null;
        // 也可设置为透明背景,效果一致
        // platformView.SetBackgroundColor(Android.Graphics.Color.Transparent);
    }
}
  1. 在MauiProgram.cs中注册Handler:
var builder = MauiApp.CreateBuilder();
builder
    .UseMauiApp<App>()
    .ConfigureMauiHandlers(handlers =>
    {
#if ANDROID
        handlers.AddHandler(typeof(Entry), typeof(CustomEntryHandler));
#endif
    });

return builder.Build();

方法三:iOS平台的边框隐藏(按需使用)

iOS平台的Entry默认无下划线,若需隐藏可能存在的边框,可通过Handler调整:

public class CustomEntryHandler : EntryHandler
{
#if IOS
    protected override void ConnectHandler(UIKit.UITextField platformView)
    {
        base.ConnectHandler(platformView);
        // 隐藏iOS TextField的边框
        platformView.BorderStyle = UIKit.UITextBorderStyle.None;
    }
#endif
}

内容的提问来源于stack exchange,提问作者Ahmed Salama

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 00:05:06