Java tutorial
//package com.java2s; import android.content.Context; import android.content.res.TypedArray; import android.util.AttributeSet; public class Main { public static final int[] ANDROID_ATTR_TEXT_APPEARANCE = new int[] { android.R.attr.textAppearance }; /** * Tries to pull the Font Path from the Text Appearance. * * @param context Activity Context * @param attrs View Attributes * @param attributeId if -1 returns null. * @return returns null if attribute is not defined or if no TextAppearance is found. */ static String pullFontPathFromTextAppearance(final Context context, AttributeSet attrs, int[] attributeId) { if (attributeId == null || attrs == null) { return null; } int textAppearanceId = -1; final TypedArray typedArrayAttr = context.obtainStyledAttributes(attrs, ANDROID_ATTR_TEXT_APPEARANCE); if (typedArrayAttr != null) { try { textAppearanceId = typedArrayAttr.getResourceId(0, -1); } catch (Exception ignored) { // Failed for some reason return null; } finally { typedArrayAttr.recycle(); } } final TypedArray textAppearanceAttrs = context.obtainStyledAttributes(textAppearanceId, attributeId); if (textAppearanceAttrs != null) { try { return textAppearanceAttrs.getString(0); } catch (Exception ignore) { // Failed for some reason. return null; } finally { textAppearanceAttrs.recycle(); } } return null; } }