2017-07-20 129 views
0

錯誤說「這個名字‘字體’並不在當前的背景下存在」如何在Xamarin.Android中使用自定義字體?字體問題

protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 

     TextView title = FindViewById<TextView>(Resource.Id.title); 
     var font = Typeface.CreateFromAsset(Assets, "FluoGums.ttf"); 
     title.Typeface = font; 

    } 
} 
+1

添加使用條款:'使用Android.Graphics;'或完全限定它:'Android.Graphics.Typeface' – SushiHangover

回答

0

你可以不喜歡這樣。

  1. 創建資源目錄中一個新的字體目錄,並把這裏的FluoGums.ttf字體文件

  2. 附加代碼在onCreate()方法

    @Override 
    protected void onCreate(@Nullable Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_splash); 
    
        TextView title = (TextView) findViewById(R.id.title); 
    
        AssetManager assetManager = getAssets(); 
    
        Typeface tf = Typeface.createFromAsset(assetManager, "fonts/FluoGums.ttf"); 
    
        title.setTypeface(tf); 
    }