Customize fonts for Hybrid App messages and the Hybrid Web Container.
<?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="com.sybase.hwc.CustomFontTextView" > <attr name="customFont" format="string"/> </declare-styleable> </resources>
package com.sybase.hwc; import android.content.Context; import android.widget.TextView; import android.text.TextUtils; import android.util.AttributeSet; import android.content.res.TypedArray; import android.graphics.Typeface; public class CustomFontTextView extends TextView { public CustomFontTextView( Context oContext ) { super( oContext ); } public CustomFontTextView( Context oContext, AttributeSet oAttrs ) { super( oContext, oAttrs ); setCustomFont( oContext, oAttrs, R.styleable.com_sybase_hwc_CustomFontTextView, R.styleable.com_sybase_hwc_CustomFontTextView_customFont ); } private void setCustomFont( Context oContext, AttributeSet oAttrs, int[] aiAttributeSet, int iFontId) { TypedArray taStyledAttributes = oContext.obtainStyledAttributes( oAttrs, aiAttributeSet ); String sCustomFont = taStyledAttributes.getString( iFontId ); if( !TextUtils.isEmpty( sCustomFont ) ) { Typeface oTypeFace = null; try { oTypeFace = getFont( oContext, sCustomFont ); setTypeface( oTypeFace ); } catch (Exception e) { System.out.println( "Count not set font!" ); // can't set the font } } else { System.out.println( "Custom font string was empty!" ); } } private Typeface getFont( Context oContext, String sCustomFont ) { String sFullCustomFont = "fonts/" + sCustomFont; Typeface oTypeFace = Typeface.createFromAsset( oContext.getAssets(), sFullCustomFont ); return oTypeFace; } }
xmlns:custom="http://schemas.android.com/apk/res/com.sybase.hwc"
custom:customFont="<NAME_OF_YOUR_FONT_FILE.TTF>"
tf.setTypeface( tf.getTypeface(), Typeface.BOLD ); tf.setTypeface( tf.getTypeface(), Typeface.NORMAL );