C# 如何在Xamarin MvvmCross中设置字体的字体
我有一个自定义的C# 如何在Xamarin MvvmCross中设置字体的字体,c#,xamarin,xamarin.android,mvvmcross,C#,Xamarin,Xamarin.android,Mvvmcross,我有一个自定义的文本视图: 我的Baskerville.ttc的选项 <Stella.Droid.Addons.CustomTextViewBaskervilleItalic android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#838383"
文本视图
:
我的Baskerville.ttc的选项
<Stella.Droid.Addons.CustomTextViewBaskervilleItalic
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#838383"
android:textSize="30sp"
android:paddingRight="4dp"
android:text="@string/ff_we_think_you_will" />
public class CustomTextViewBaskervilleItalic : TextView
{
private string text;
public CustomTextViewBaskervilleItalic(Context context) :
base(context)
{
Initialize(text);
}
public CustomTextViewBaskervilleItalic(Context context, IAttributeSet attrs) :
base(context, attrs)
{
text = context.Resources.ObtainAttributes(attrs, Resource.Styleable.customfont).GetString(Resource.Styleable.customfont_textformat);
Initialize(text);
}
public CustomTextViewBaskervilleItalic(Context context, IAttributeSet attrs, int defStyle) :
base(context, attrs, defStyle)
{
text = context.Resources.ObtainAttributes(attrs, Resource.Styleable.customfont).GetString(Resource.Styleable.customfont_textformat);
Initialize(text);
}
void Initialize(string format)
{
Typeface leagueFont;
if (format != null)
{
leagueFont = Typeface.CreateFromAsset(Application.Context.Assets, format);
}
else
{
leagueFont = Typeface.CreateFromAsset(Application.Context.Assets, "fonts/Baskerville.ttc");
}
SetTypeface(leagueFont, TypefaceStyle.BOLD);
}
}
如何从.ttc文件设置半黑体字体样式您是否可以修改代码的这一部分[SetTypeface(leagueFont,TypefaceStyle.BOLD);]呢?但这不是从.ttc文件设置字体,例如,如果我将字体设置为斜体。。。。字符完全不同控件初始化后是否尝试设置字体和类型样式?确定这些属性是否在控件实例化的早期设置。我认为这正是您需要的: