无法设置自定义字体
Cannot set custom font
我想给自己的 EditText
class 一个字体
public class MyEditText : EditText
{
public MyEditText(Context context) : base(context)
{
InitializeView(context);
}
public MyEditText (Context context, IAttributeSet attrs) : base(context, attrs)
{
InitializeView(context);
}
public MyEditText (Context context, IAttributeSet attrs, int defStyle) : base(context,attrs,defStyle)
{
InitializeView(context);
}
private void InitializeView(Context context)
{
this.Typeface = Typeface.CreateFromAsset(Context.Assets, "Fonts/segoeui.ttf");
}
}
但我得到的只是这个错误
Error CS0176: Member
'Android.Graphics.Typeface.CreateFromAsset(Android.Content.Res.AssetManager,
string)' cannot be accessed with an instance reference; qualify it
with a type name instead
我已经尝试过 Application.Context
,但没有用。
为什么会这样?
它混淆了 class 的类型空间 属性 和 Android.Graphics
的字体 class
this.Typeface = Android.Graphics.Typeface.CreateFromAsset(Context.Assets, "Fonts/segoeui.ttf");
我想给自己的 EditText
class 一个字体
public class MyEditText : EditText
{
public MyEditText(Context context) : base(context)
{
InitializeView(context);
}
public MyEditText (Context context, IAttributeSet attrs) : base(context, attrs)
{
InitializeView(context);
}
public MyEditText (Context context, IAttributeSet attrs, int defStyle) : base(context,attrs,defStyle)
{
InitializeView(context);
}
private void InitializeView(Context context)
{
this.Typeface = Typeface.CreateFromAsset(Context.Assets, "Fonts/segoeui.ttf");
}
}
但我得到的只是这个错误
Error CS0176: Member 'Android.Graphics.Typeface.CreateFromAsset(Android.Content.Res.AssetManager, string)' cannot be accessed with an instance reference; qualify it with a type name instead
我已经尝试过 Application.Context
,但没有用。
为什么会这样?
它混淆了 class 的类型空间 属性 和 Android.Graphics
的字体 classthis.Typeface = Android.Graphics.Typeface.CreateFromAsset(Context.Assets, "Fonts/segoeui.ttf");