私のアプリケーションのすべてのビューにカスタムフォントを使用しています。しかし、現在のフォントはツールバーにのみ適用され、残りのビューはデフォルトのフォントを使用します。これは、バージョン23.4.0.1へのappcompat lib updateの副作用で発生しました。誰かがこの問題を経験していますか?フォントの使用クラスの下appcompatライブラリを23.4.0.1にアップデートした後、カスタムフォントが機能しない
FontUtility.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Graphics;
namespace HPScanJA.Android.Utils
{
class FontUtility
{
public static Typeface applyRegularFont(Context context)
{
Typeface hpRegularTypeface = Typeface.CreateFromAsset(context.Assets, "fonts/Simplified_Rg.ttf");
return hpRegularTypeface;
}
public static Typeface applyBoldFont(Context context)
{
Typeface hpBoldTypeface = Typeface.CreateFromAsset(context.Assets, "fonts/Simplified_Bd.ttf");
return hpBoldTypeface;
}
}
}
も使用量が、以下に示す基本活動であるを見つけてください。これは親切に、誰もがこの問題に直面した場合、私に知らせて、すべての活動による
BaseActivity.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Graphics;
using HPScanJA.Android.Utils;
using Android.Support.V7.App;
namespace HPScanJA.Android.Activities
{
[Activity(Label = "BaseActivity")]
public class BaseActivity : AppCompatActivity
{
Context context;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
context = this;
// Get the Resources object from our context
global::Android.Content.Res.Resources res = context.Resources;
// Create your application here
int titleId = res.GetIdentifier("action_bar_title", "id",
"android");
TextView titleView = (TextView)FindViewById(titleId);
if (titleView != null)
titleView.SetTypeface(FontUtility.applyRegularFont(context), TypefaceStyle.Normal);
}
public override View OnCreateView(string name, Context context, global::Android.Util.IAttributeSet attrs)
{
View view = base.OnCreateView(name, context, attrs);
return setCustomTypeFaceIfNeeded(name, attrs, view);
}
protected View setCustomTypeFaceIfNeeded(String name, global::Android.Util.IAttributeSet attrs, View view)
{
View result = null;
Console.WriteLine("*******************************************"+name+"*******************************************");
if ("TextView".Equals(name))
{
result = new TextView(this, attrs);
if (null != ((TextView)result).Typeface && TypefaceStyle.Bold == ((TextView)result).Typeface.Style)
{
((TextView)result).SetTypeface(FontUtility.applyBoldFont(context), TypefaceStyle.Normal);
}
else
{
((TextView)result).SetTypeface(FontUtility.applyRegularFont(context), TypefaceStyle.Normal);
}
}
else if ("EditText".Equals(name))
{
result = new EditText(this, attrs);
if (null != ((EditText)result).Typeface && TypefaceStyle.Bold == ((EditText)result).Typeface.Style)
{
((EditText)result).SetTypeface(FontUtility.applyBoldFont(context), TypefaceStyle.Normal);
}
else
{
((EditText)result).SetTypeface(FontUtility.applyRegularFont(context), TypefaceStyle.Normal);
}
}
else if ("Button".Equals(name))
{
result = new Button(this, attrs);
if (null != ((Button)result).Typeface && TypefaceStyle.Bold == ((Button)result).Typeface.Style)
{
((Button)result).SetTypeface(FontUtility.applyBoldFont(context), TypefaceStyle.Normal);
}
else
{
((Button)result).SetTypeface(FontUtility.applyRegularFont(context), TypefaceStyle.Normal);
}
}
else if ("CheckedTextView".Equals(name))
{
result = new CheckedTextView(this, attrs);
if (null != ((CheckedTextView)result).Typeface && TypefaceStyle.Bold == ((CheckedTextView)result).Typeface.Style)
{
((CheckedTextView)result).SetTypeface(FontUtility.applyBoldFont(context), TypefaceStyle.Normal);
}
else
{
((CheckedTextView)result).SetTypeface(FontUtility.applyRegularFont(context), TypefaceStyle.Normal);
}
}
else if ("CheckBox".Equals(name))
{
result = new CheckBox(this, attrs);
if (null != ((CheckBox)result).Typeface && TypefaceStyle.Bold == ((CheckBox)result).Typeface.Style)
{
((CheckBox)result).SetTypeface(FontUtility.applyBoldFont(context), TypefaceStyle.Normal);
}
else
{
((CheckBox)result).SetTypeface(FontUtility.applyRegularFont(context), TypefaceStyle.Normal);
}
}
else if ("RadioButton".Equals(name))
{
result = new RadioButton(this, attrs);
if (null != ((RadioButton)result).Typeface && TypefaceStyle.Bold == ((RadioButton)result).Typeface.Style)
{
((RadioButton)result).SetTypeface(FontUtility.applyBoldFont(context), TypefaceStyle.Normal);
}
else
{
((RadioButton)result).SetTypeface(FontUtility.applyRegularFont(context), TypefaceStyle.Normal);
}
}
else if ("Switch".Equals(name))
{
result = new Switch(this, attrs);
if (null != ((Switch)result).Typeface && TypefaceStyle.Bold == ((Switch)result).Typeface.Style)
{
((Switch)result).SetTypeface(FontUtility.applyBoldFont(context), TypefaceStyle.Normal);
}
else
{
((Switch)result).SetTypeface(FontUtility.applyRegularFont(context), TypefaceStyle.Normal);
}
}
if (result == null)
{
return view;
}
else
{
return result;
}
}
}
}
を拡張します。
:23.4.0.1、これができない..ですちょうどのみ23.4.0を使用する。これは、Androidのサポートライブラリのアップデート版である1 –
を削除します。私は最後に追加したものでもありません。バージョン番号はアップデート –
と一緒にアップしましたが、最新のアップデートされたライブラリは24.1.1です。http://gradleplease.appspot.com/ここで見つけることができます。 –