Xamrin.Forms输入单元格如何更改占位符的字体大小

编程入门 行业动态 更新时间:2024-10-25 02:20:14
本文介绍了Xamrin.Forms输入单元格如何更改占位符的字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在想是否可以更改EntryCell上的占位符的字体大小而不更改fontSize上的文本的fontSize吗?

I am thinking if i can change font size for placeholder on EntryCell without change fontSize for Text on EntryCell?

是否可以更改占位符的字体大小而无需更改文本的字体大小

Is There away to change font size for Placeholder without change font size for Text

Code = new EntryCell { Label = "Code:*", Text = "", Keyboard = Keyboard.Default, Placeholder = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" };

推荐答案

这是针对Android的自定义渲染器.在这里,我正在修改HintTextColor(placeholder).您可以用类似的方式修改字体.

Here is a custom renderer for android. Here I'm modifying the HintTextColor(placeholder). You can modify the font in a similar way.

using System; using Xamarin.Forms.Platform.Android; using Xamarin.Forms; using communityhealth; using Android.Graphics; using communityhealth.Android; [assembly: ExportRenderer (typeof (MyUsernameEntry), typeof (MyUsernameEntryRenderer))] [assembly: ExportRenderer (typeof (MyPasswordEntry), typeof (MyPasswordEntryRenderer))] [assembly: ExportRenderer (typeof (MyEntry), typeof (MyEntryRenderer))] namespace communityhealth.Android { public class MyEntryRenderer : EntryRenderer { protected override void OnElementChanged (ElementChangedEventArgs<Entry> e) { base.OnElementChanged (e); if (e.OldElement == null) { // perform initial setup // lets get a reference to the native control var nativeEditText = (global::Android.Widget.EditText) Control; // do whatever you want to the textField here! nativeEditText.SetBackgroundColor(global::Android.Graphics.Color.Transparent); nativeEditText.SetTextColor(global::Android.Graphics.Color.White); Typeface font = Typeface.CreateFromAsset (Forms.Context.Assets, "Neris-Light.otf"); nativeEditText.TextSize = 14f; nativeEditText.Typeface = font; } } } public class MyUsernameEntryRenderer : MyEntryRenderer { protected override void OnElementChanged (ElementChangedEventArgs<Entry> e) { base.OnElementChanged (e); if (e.OldElement == null) { // lets get a reference to the native control var nativeEditText = (global::Android.Widget.EditText) Control; nativeEditText.Hint = "Username"; nativeEditText.SetHintTextColor (global::Android.Graphics.Color.White); nativeEditText.TextSize = 18f; } } } public class MyPasswordEntryRenderer : MyEntryRenderer { protected override void OnElementChanged (ElementChangedEventArgs<Entry> e) { base.OnElementChanged (e); if (e.OldElement == null) { // lets get a reference to the native control var nativeEditText = (global::Android.Widget.EditText) Control; nativeEditText.Hint = "Password"; nativeEditText.SetHintTextColor (global::Android.Graphics.Color.White); nativeEditText.TextSize = 18f; } } } }

更多推荐

Xamrin.Forms输入单元格如何更改占位符的字体大小

本文发布于:2023-10-07 10:38:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469164.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字体大小   单元格   如何更改   Xamrin   Forms

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!