Note that there are some explanatory texts on larger screens.

plurals
  1. POModifying font in title causes error
    primarykey
    data
    text
    <p>I've tried the first two answers in the following post for changing the font of my title: <a href="https://stackoverflow.com/questions/8607707/how-to-set-a-custom-font-in-the-actionbar-title">How to Set a Custom Font in the ActionBar Title?</a> and I get the message in my emulator:</p> <pre><code>Unfortunately, DC Parks has stopped. OK </code></pre> <p>Going with the second answer here is my MainActivity code:</p> <pre><code>import android.app.ActionBar; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.text.Spannable; import android.text.SpannableString; import android.view.Menu; import android.view.View; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SpannableString s = new SpannableString("My Title"); s.setSpan(new TypefaceSpan(this, "MotorwerkOblique.ttf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); //Update the action bar title with the TypefaceSpan instance ActionBar actionBar = getActionBar(); actionBar.setTitle(s); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void test(View view) { //Intent represents the app's 'intent to do something' Intent intent = new Intent(this, NewPage.class); //have to create the new_page activity startActivity(intent); } public void textclick(View myview) { Intent myintent = new Intent(this, NewPage.class); startActivity(myintent); } } </code></pre> <p>TypefaceSpan.java code:</p> <pre><code>public class TypefaceSpan extends MetricAffectingSpan { /** An &lt;code&gt;LruCache&lt;/code&gt; for previously loaded typefaces. */ private static LruCache&lt;String, Typeface&gt; sTypefaceCache = new LruCache&lt;String, Typeface&gt;(12); private Typeface mTypeface; /** * Load the {@link Typeface} and apply to a {@link Spannable}. */ public TypefaceSpan(Context context, String typefaceName) { mTypeface = sTypefaceCache.get(typefaceName); if (mTypeface == null) { mTypeface = Typeface.createFromAsset(context.getApplicationContext() .getAssets(), String.format("fonts/%s.otf", typefaceName)); // Cache the loaded Typeface sTypefaceCache.put(typefaceName, mTypeface); } } @Override public void updateMeasureState(TextPaint p) { p.setTypeface(mTypeface); // Note: This flag is required for proper typeface rendering p.setFlags(p.getFlags() | Paint.SUBPIXEL_TEXT_FLAG); } @Override public void updateDrawState(TextPaint tp) { tp.setTypeface(mTypeface); // Note: This flag is required for proper typeface rendering tp.setFlags(tp.getFlags() | Paint.SUBPIXEL_TEXT_FLAG); } } </code></pre> <p>My font is located in assests/fonts/MotorwerkObliqhue.ttf</p> <p>Any help would be greatly appreciated!</p> <p>From Console:</p> <pre><code>[2013-11-20 14:54:58 - DCParks] Dx trouble writing output: already prepared [2013-11-20 14:55:00 - DCParks] ------------------------------ [2013-11-20 14:55:00 - DCParks] Android Launch! [2013-11-20 14:55:00 - DCParks] adb is running normally. [2013-11-20 14:55:00 - DCParks] Performing com.example.dcparks.MainActivity activity launch [2013-11-20 14:55:00 - DCParks] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'Nexus4' [2013-11-20 14:55:00 - DCParks] Uploading DCParks.apk onto device 'emulator-5554' [2013-11-20 14:55:05 - DCParks] Installing DCParks.apk... [2013-11-20 14:55:13 - DCParks] Success! [2013-11-20 14:55:13 - DCParks] Starting activity com.example.dcparks.MainActivity on device emulator-5554 [2013-11-20 14:55:16 - DCParks] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.dcparks/.MainActivity } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload