Example usage for android.widget TextView setTypeface

List of usage examples for android.widget TextView setTypeface

Introduction

In this page you can find the example usage for android.widget TextView setTypeface.

Prototype

public void setTypeface(@Nullable Typeface tf, @Typeface.Style int style) 

Source Link

Document

Sets the typeface and style in which the text should be displayed, and turns on the fake bold and italic bits in the Paint if the Typeface that you provided does not have all the bits in the style that you specified.

Usage

From source file:Main.java

public static void TextView_setFontBold(TextView v) {
    v.setTypeface(null, Typeface.BOLD);
}

From source file:Main.java

/**
 * Sets a determined font on a text view element
 *
 * @param context   Context in which the TextView can be found
 * @param font      Font to be set in the text view see available fonts as static attributes of this class
 * @param style     {@see Typeface}/*from www.j a va 2 s. com*/
 * @param textViews TextViews to which the font will be applied
 */
public static void setTypeface(Context context, String font, int style, TextView... textViews) {
    Typeface tf = Typeface.createFromAsset(context.getAssets(), font);
    for (TextView txt : textViews) {
        txt.setTypeface(tf, style);
    }
}

From source file:com.google.android.apps.iosched.util.UIUtils.java

public static void updateTimeAndLivestreamBlockUI(final Context context, long blockStart, long blockEnd,
        boolean hasLivestream, View backgroundView, TextView titleView, TextView subtitleView,
        CharSequence subtitle) {/* w  w w .  ja  va 2 s .co  m*/
    long currentTimeMillis = getCurrentTime(context);

    boolean past = (currentTimeMillis > blockEnd && currentTimeMillis < CONFERENCE_END_MILLIS);
    boolean present = (blockStart <= currentTimeMillis && currentTimeMillis <= blockEnd);

    final Resources res = context.getResources();
    if (backgroundView != null) {
        backgroundView.setBackgroundColor(past ? res.getColor(R.color.past_background_color) : 0);
    }

    if (titleView != null) {
        titleView.setTypeface(Typeface.SANS_SERIF, past ? Typeface.NORMAL : Typeface.BOLD);
    }

    if (subtitleView != null) {
        boolean empty = true;
        SpannableStringBuilder sb = new SpannableStringBuilder(); // TODO: recycle
        if (subtitle != null) {
            sb.append(subtitle);
            empty = false;
        }

        if (present) {
            if (sNowPlayingText == null) {
                sNowPlayingText = Html.fromHtml(context.getString(R.string.now_playing_badge));
            }
            if (!empty) {
                sb.append("  ");
            }
            sb.append(sNowPlayingText);

            if (hasLivestream) {
                if (sLivestreamNowText == null) {
                    sLivestreamNowText = Html
                            .fromHtml("&nbsp;&nbsp;" + context.getString(R.string.live_now_badge));
                }
                sb.append(sLivestreamNowText);
            }
        } else if (hasLivestream) {
            if (sLivestreamAvailableText == null) {
                sLivestreamAvailableText = Html.fromHtml(context.getString(R.string.live_available_badge));
            }
            if (!empty) {
                sb.append("  ");
            }
            sb.append(sLivestreamAvailableText);
        }

        subtitleView.setText(sb);
    }
}

From source file:com.messagesight.mqtthelper.PayloadAdapter.java

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    String headerTitle = (String) getGroup(groupPosition);
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) this.ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.list_group, null);
    }//from  w  ww  .ja  va2s . co  m

    TextView lblListHeader = (TextView) convertView.findViewById(R.id.lblListHeader);
    lblListHeader.setTypeface(null, Typeface.BOLD);
    String[] tempTitle = headerTitle.split(":");
    headerTitle = tempTitle[0];
    lblListHeader.setText(headerTitle);
    return convertView;
}

From source file:com.ephemeraldreams.gallyshuttle.ui.adapters.NavigationDrawerAdapter.java

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    String headerText = headers[groupPosition];
    if (convertView == null) {
        convertView = layoutInflater.inflate(R.layout.navigation_list_group, parent, false);
    }/* w  w  w  .  j  a  va2s .  com*/
    TextView headerTextView = ButterKnife.findById(convertView, R.id.navigation_drawer_header_text_view);
    headerTextView.setTypeface(null, Typeface.BOLD);
    headerTextView.setText(headerText);
    return convertView;
}

From source file:com.google.samples.apps.iosched.util.LPreviewUtilsBase.java

public void setMediumTypeface(TextView textView) {
    textView.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD);
}

From source file:com.bobomee.android.gank.io.widget.CompactTabLayout.java

private void renderSelectedText(TextView textView) {
    // textView.setTextSize(14);
    textView.setTypeface(null, Typeface.BOLD);
}

From source file:com.bobomee.android.gank.io.widget.CompactTabLayout.java

private void renderNormalText(TextView textView) {
    // textView.setTextSize(14);
    textView.setTypeface(null, Typeface.NORMAL);
}

From source file:com.example.android.capstone.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from w  ww .  ja v  a2  s  .com*/
    TextView myTitle = (TextView) toolbar.getChildAt(0);
    Typeface tf = Typeface.createFromAsset(getAssets(), getResources().getString(R.string.font_name));
    myTitle.setTypeface(tf, Typeface.BOLD);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(getResources().getString(R.string.ad_device_test)).build();
    mAdView.loadAd(adRequest);
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
    viewPager.setAdapter(new PagerAdapter(getSupportFragmentManager()));
    TabLayout tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
    tabLayout.setupWithViewPager(viewPager);
}

From source file:ch.pantas.billsplitter.ui.FixedTabsView.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {
        TextView v = (TextView) tabsContainer.getChildAt(i);

        TextView tab = (TextView) v;
        tab.setTextSize(TypedValue.COMPLEX_UNIT_DIP, tabTextSize);
        tab.setTypeface(tabTypeface, tabTypefaceStyle);
        tab.setTextColor(tabTextColor);/*from w  w w  .jav  a  2s  .  c om*/

        tab.setAllCaps(textAllCaps);
    }

}