1

の作品ではない、事はしてください、それはロリポップ未満とlolliopより大きいアンドロイドのバージョンで動作しますが、ロリポップに、それはちょうど空白カスタム書体は、Android 5.0での作業が、私は私のアプリでカスタムフォントを使用しています他の場所

を行く、ですボタンはカスタムフォントを使用して接続コードやスクリーンショット

SelectionPage.java

package com.execube.volantis.views; 

import android.content.Intent; 
import android.graphics.Color; 
import android.graphics.Typeface; 
import android.net.Uri; 
import android.os.Build; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.view.WindowManager; 
import android.view.animation.AccelerateDecelerateInterpolator; 
import android.widget.Button; 
import android.widget.ImageView; 
import android.widget.TextView; 

import com.crashlytics.android.Crashlytics; 
import com.execube.volantis.R; 
import com.execube.volantis.receiver.customHandler; 
import com.flaviofaria.kenburnsview.KenBurnsView; 
import com.flaviofaria.kenburnsview.RandomTransitionGenerator; 
import com.pushbots.push.Pushbots; 

import io.fabric.sdk.android.Fabric; 

public class SelectionPage extends AppCompatActivity { 

    private Button mEventsButton; 
    private Button mAlertsButton; 
    private Button mAboutButton; 
    private Button mDirectionsButton; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     Fabric.with(this, new Crashlytics()); 
     setContentView(R.layout.selection_page); 

     Pushbots.sharedInstance().init(this); 

     Pushbots.sharedInstance().setCustomHandler(customHandler.class); 











     mEventsButton=(Button)findViewById(R.id.events_button); 
     mAboutButton=(Button)findViewById(R.id.about_button); 
     mAlertsButton=(Button)findViewById(R.id.alerts_button); 
     mDirectionsButton=(Button)findViewById(R.id.directions_button); 




      Typeface gothamRoundedMedium= Typeface.createFromAsset(getAssets(),"fonts/Gotham-Rounded-Medium.ttf"); 
      mEventsButton.setTypeface(gothamRoundedMedium); 
     mAboutButton.setTypeface(gothamRoundedMedium); 
     mDirectionsButton.setTypeface(gothamRoundedMedium); 
     mAlertsButton.setTypeface(gothamRoundedMedium); 





     mEventsButton.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent intent= new Intent(SelectionPage.this,EventActivity.class); 

       startActivity(intent); 
      } 
     }); 


     mDirectionsButton.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       String geoUri = "http://maps.google.com/maps?q=loc:" + "12.9021902" + "," + "77.518582" + " (" + "RNS Institute Of Technlogy" + ")"; 
       Intent intent= new Intent(Intent.ACTION_VIEW, Uri.parse(geoUri)); 
       startActivity(intent); 
      } 
     }); 

     mAlertsButton.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent intent= new Intent(SelectionPage.this,AlertsActivity.class); 
       startActivity(intent); 
      } 
     }); 

     mAboutButton.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent intent= new Intent(SelectionPage.this,AboutActivity.class); 
       startActivity(intent); 
      } 
     }); 

    } 
} 

を見つけます。

アンドロイド版がLollipopと等しくない場合にのみカスタムフォントを設定する方法はありますか?

ここマシュマロAPI 23

**Here's Marshmallow API 23**

ここだロリポップAPIだ21

enter image description here

+0

ます。https:// androidbycode。 wordpress.com/2015/06/02/help-my-custom-font-does-not-work-on-android-5-0/あなたに役立つかもしれません – saeed

答えて

0

アプリケーションクラスでタイプフェイスを定義します。

public final class FontsOverride { 

public static void setDefaultFont(Context context, 
     String staticTypefaceFieldName, String fontAssetName) { 
    final Typeface regular = Typeface.createFromAsset(context.getAssets(), 
      fontAssetName); 
    replaceFont(staticTypefaceFieldName, regular); 
} 

protected static void replaceFont(String staticTypefaceFieldName, 
     final Typeface newTypeface) { 
    try { 
     final Field staticField = Typeface.class 
       .getDeclaredField(staticTypefaceFieldName); 
     staticField.setAccessible(true); 
     staticField.set(null, newTypeface); 
    } catch (NoSuchFieldException e) { 
     e.printStackTrace(); 
    } catch (IllegalAccessException e) { 
     e.printStackTrace(); 
    } 
} 
} 

あなたは、アプリケーションのクラス、例えば、いくつかのデフォルトのフォントをオーバーロードする必要があります。

public final class Application extends android.app.Application { 
@Override 
public void onCreate() { 
    super.onCreate(); 
    FontsOverride.setDefaultFont(this, "DEFAULT", "MyFontAsset.ttf"); 
    } 
} 

API 21のAndroid 5.0を使用するデフォルトのテーマ

<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar"> 
<item name="android:typeface">monospace</item> 
</style> 
関連する問題