使用.NET MAUI的Entry控件时出现下划线,如何移除?
移除.NET MAUI Entry控件的下划线
方法一:直接设置控件属性(最简便)
在XAML中给Entry添加UnderlineColor属性,将其设为透明即可:
<Entry Placeholder="Username" UnderlineColor="Transparent" />
如果用C#代码后台设置:
var entry = new Entry { Placeholder = "Username", UnderlineColor = Colors.Transparent };
方法二:全局样式(统一所有Entry)
如果需要项目中所有Entry都去掉下划线,可以在App.xaml中定义全局样式:
<Application.Resources> <Style TargetType="Entry"> <Setter Property="UnderlineColor" Value="Transparent" /> </Style> </Application.Resources>
特殊情况:Android平台额外处理(若上述方法不生效)
极少数情况下,Android原生样式会覆盖设置,可在Platforms/Android/Resources/values/styles.xml中修改:
<style name="MyTheme" parent="MainTheme.Base"> <item name="android:textColorHint">#666666</item> <!-- 移除下划线 --> <item name="colorControlNormal">@android:color/transparent</item> <item name="colorControlActivated">@android:color/transparent</item> </style>
内容的提问来源于stack exchange,提问作者Mustafa Gönültaş
相关产品推荐
相关产品推荐

