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:base.PagerSlidingTabStrip.java

private void notSelected(View tab) {
    TextView title = (TextView) tab.findViewById(R.id.tab_title);
    if (title != null) {
        title.setTypeface(tabTypeface, tabTypefaceStyle);
        ViewCompat.setAlpha(title, tabTextAlpha);
    }//  w ww . j  av  a  2s.  c o  m
}

From source file:base.PagerSlidingTabStrip.java

private void selected(View tab) {
    TextView title = (TextView) tab.findViewById(R.id.tab_title);
    if (title != null) {
        title.setTypeface(tabTypeface, tabTypefaceSelectedStyle);
        ViewCompat.setAlpha(title, tabTextSelectedAlpha);
    }//from w  w w . j a  v  a 2 s. c  o m
}

From source file:cc.wudoumi.framework.views.PagerSlidingTabStrip.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        v.setBackgroundResource(tabBackgroundResId);

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            //tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            updateTabTextSize(tab);//from w  w  w . j a  v a2 s.  c om
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            //tab.setTextColor(textColor);

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }
            }
        }
    }

}

From source file:com.cyanogenmod.eleven.widgets.ViewPagerTabs.java

private void addTab(CharSequence tabTitle, final int position) {
    final TextView textView = new TextView(getContext());
    textView.setText(tabTitle);//  w ww  .j  a va2 s .c  o m
    textView.setBackgroundResource(R.drawable.view_pager_tab_background);
    textView.setGravity(Gravity.CENTER);
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mPager.setCurrentItem(getRtlPosition(position));
        }
    });

    textView.setOnLongClickListener(new OnTabLongClickListener(position));

    // Assign various text appearance related attributes to child views.
    if (mTextStyle > 0) {
        textView.setTypeface(textView.getTypeface(), mTextStyle);
    }
    if (mTextSize > 0) {
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
    }
    if (mTextColor != null) {
        textView.setTextColor(mTextColor);
    }
    textView.setAllCaps(mTextAllCaps);
    textView.setPadding(mSidePadding, 0, mSidePadding, 0);
    mTabStrip.addView(textView,
            new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1));
    // Default to the first child being selected
    if (position == 0) {
        mPrevSelected = 0;
        textView.setSelected(true);
    }
}

From source file:com.astuetz.PagerSlidingTabStripCustom.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        v.setBackgroundResource(tabBackgroundResId);

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);//TODO
            //            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            //                tab.setTextColor(tabTextColor);
            tab.setTextColor(textColor);//TODO

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }/* w  w w .ja  v a  2s.c  o  m*/
            }
            //TODO  ?pageTitle?
            if (mCurrentPosition == i) {
                tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, selectTextSize);
                tab.setTextColor(selectTextColor);
            }
        }
    }

}

From source file:com.example.fan.horizontalscrollview.PagerSlidingTabStrip.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        v.setLayoutParams(defaultTabLayoutParams);
        v.setBackgroundResource(tabBackgroundResId);
        v.setPadding(tabPadding, 0, tabPadding, 0);

        if (v instanceof TextView || v instanceof RelativeLayout) {
            TextView tab = null;
            if (v instanceof TextView)
                tab = (TextView) v;//from ww  w .  ja va  2  s. c  o m
            else
                tab = (TextView) v.findViewById(R.id.pst_tv_tab);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }
            }
        }
    }

}

From source file:com.frozendevs.periodictable.view.ViewPagerTabs.java

private void addTab(CharSequence tabTitle, final int position) {
    final TextView textView = new TextView(getContext());
    textView.setText(tabTitle);/*from www .j a va 2s . c  o  m*/
    textView.setGravity(Gravity.CENTER);
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mPager.setCurrentItem(getRtlPosition(position));
        }
    });

    /* We don't need this as far as we use text tabs only
    textView.setOnLongClickListener(new OnTabLongClickListener(position));*/

    // Assign various text appearance related attributes to child views.
    if (mTextStyle > 0) {
        textView.setTypeface(textView.getTypeface(), mTextStyle);
    }
    if (mTextSize > 0) {
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
    }
    if (mTextColor != null) {
        textView.setTextColor(mTextColor);
    }
    if (mTextBackground > 0) {
        textView.setBackgroundResource(mTextBackground);
    }
    textView.setText(
            textView.getText().toString().toUpperCase(getContext().getResources().getConfiguration().locale));
    textView.setPadding(mSidePadding, 0, mSidePadding, 0);
    mTabStrip.addView(textView, new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1));
    // Default to the first child being selected
    if (position == 0) {
        mPrevSelected = 0;
        textView.setSelected(true);
    }
}

From source file:com.astuetz.PagerSlidingTabStripPlus.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        for (int k = 0; k < ((LinearLayout) tabsContainer.getChildAt(i)).getChildCount(); k++) {

            View v = ((LinearLayout) tabsContainer.getChildAt(i)).getChildAt(k);

            v.setBackgroundResource(tabBackgroundResId);

            if (v instanceof TextView) {

                TextView tab = (TextView) v;
                tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
                tab.setTypeface(tabTypeface, tabTypefaceStyle);

                // Setting color of textView
                if (textColorTab != null) {
                    tab.setTextColor(textColorTab);
                } else {
                    tab.setTextColor(Color.BLACK);
                }/*w  w  w. j  a v a 2  s .co  m*/

                // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
                // pre-ICS-build
                if (textAllCaps) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                        tab.setAllCaps(true);
                    } else {
                        tab.setText(tab.getText().toString().toUpperCase(locale));
                    }
                }
            }
        }
    }
}

From source file:com.ashish.routofy.PagerSlidingTabStrip.java

private void notSelected(View tab) {
    if (tab != null) {
        TextView title = (TextView) tab.findViewById(R.id.psts_tab_title);
        if (title != null) {
            title.setTypeface(tabTypeface, tabTypefaceStyle);
            title.setTextColor(tabTextColor);
        }/*from  www.  j ava 2s  . com*/
    }
}

From source file:com.ashish.routofy.PagerSlidingTabStrip.java

private void selected(View tab) {
    if (tab != null) {
        TextView title = (TextView) tab.findViewById(R.id.psts_tab_title);
        if (title != null) {
            title.setTypeface(tabTypeface, tabTypefaceSelectedStyle);
            title.setTextColor(tabTextColorSelected);
        }//w  w w .jav a  2  s.  co m
    }
}