如何减少xamarin表单中占位符的字体大小?
我有一个用户界面,其中占位符文本适合搜索栏。这就是我需要的UI 这是我的用户界面 这是我的自定义渲染器代码如何减少xamarin表单中占位符的字体大小?,xamarin,xamarin.forms,placeholder,searchbar,Xamarin,Xamarin.forms,Placeholder,Searchbar,我有一个用户界面,其中占位符文本适合搜索栏。这就是我需要的UI 这是我的用户界面 这是我的自定义渲染器代码 [assembly: ExportRenderer(typeof(searchTab), typeof(StyledSearchBarRenderer))] namespace RestaurantApp.Droid.Renderers { #pragma warning disable CS0618 // Type or member is obsolete class St
[assembly: ExportRenderer(typeof(searchTab), typeof(StyledSearchBarRenderer))]
namespace RestaurantApp.Droid.Renderers
{
#pragma warning disable CS0618 // Type or member is obsolete
class StyledSearchBarRenderer : SearchBarRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
{
base.OnElementChanged(e);
if (Control != null)
{
var color = global::Xamarin.Forms.Color.LightGray;
var searchView = Control as SearchView;
int searchPlateId = searchView.Context.Resources.GetIdentifier("android:id/search_plate", null, null);
Android.Views.View searchPlateView = searchView.FindViewById(searchPlateId);
searchPlateView.SetBackgroundColor(Android.Graphics.Color.Transparent);
int searchIconId = Context.Resources.GetIdentifier("android:id/search_mag_icon", null, null);
ImageView searchViewIcon = (ImageView)searchView.FindViewById<ImageView>(searchIconId);
searchViewIcon.SetImageDrawable(null);
}
}
}
#pragma warning restore CS0618 // Type or member is obsolete
}
[程序集:ExportRenderer(typeof(searchTab)、typeof(styledSearchBallenderer))]
命名空间RestaurantApp.Droid.Renderers
{
#pragma warning disable CS0618//类型或成员已过时
类StyledSearchBallenderer:SearchBallenderer
{
受保护的覆盖无效OnElementChanged(ElementChangedEventArgs e)
{
基础。一个要素发生变化(e);
if(控件!=null)
{
var color=global::Xamarin.Forms.color.LightGray;
var searchView=作为searchView的控件;
int searchPlateId=searchView.Context.Resources.GetIdentifier(“android:id/search\u plate”,null,null);
Android.Views.View searchPlateView=searchView.findviewbyd(searchPlateId);
searchPlateView.SetBackgroundColor(Android.Graphics.Color.Transparent);
int searchIconId=Context.Resources.GetIdentifier(“android:id/search\u mag\u icon”,null,null);
ImageView searchViewIcon=(ImageView)searchView.FindViewById(searchIconId);
searchViewIcon.SetImageDrawable(空);
}
}
}
#pragma warning restore CS0618//类型或成员已过时
}
这是我的XAML代码
<Frame CornerRadius="10" Padding="0" OutlineColor="DarkGray" HasShadow="True" HorizontalOptions="Fill" Margin="10,0,10,0" VerticalOptions="Center">
<local:searchTab x:Name="searchBar" Placeholder="Please search for a vendor or product name" PlaceholderColor="Black" TextColor="Black" HorizontalOptions="FillAndExpand" VerticalOptions="Center" />
</Frame>
我不知道怎么解决这个问题。有什么建议吗?首先要了解的是,用户的屏幕大小会因他们使用的设备而异。将字体大小设置为绝对值会使其复杂化 保持其指导方针的简洁性,应该可以帮助您使用有利于您的应用程序的UI(即使它只针对Android)。在您的示例中,您希望显示文本
请搜索产品供应商或名称
。这是每个UI指南中的一个指令。搜索栏占位符必须是提示,例如搜索、产品、供应商、产品或供应商名称(列表继续)
您拥有的文本应显示为搜索栏上方的标签,以便用户知道这是他们必须遵循的说明。然后在搜索栏中,为搜索栏显示一个简短的占位符(上面的示例)。事实上,您可以通过将指令放在标签中来改进UI,但要使用一个示例搜索字符串作为占位符(例如:Apple iPhone),以便用户有一个编写内容的示例
或者,您可以删除“请键入…”并将搜索栏占位符用作产品/供应商名称。用户仍然知道按产品或供应商名称搜索
执行上述操作将避免创建不必要的复杂自定义渲染器。要更改
SearchView
的HintText
,我们需要找到SearchView
的EditText
var textView = (searchView.FindViewById(textViewId) as EditText);
现在,在获得SearchView
的EditText
实例后,我们可以设置textView
我们可以设置所有类型的属性,例如SetBackgroundColor
,SetHintTextColor
因此,要更改HintText
(占位符)的代码如下所示
var textView = (searchView.FindViewById(textViewId) as EditText);
textView.SetTextSize(12);
注意:当我们更改
TextSize
提示大小时,提示大小也会更改。尝试此EditText textView=(searchView.FindViewById(textViewId)作为EditText);textView.SetTextSize(12)代码>我非常确定,如果您下拉文本大小,它会将占位符管理为well@user3452-如果你不介意的话,我可以写下答案吗?当然可以@CGPA6.4