/** * Set Icon size of the button (for only font icons) in sp * * @param iconSize : Icon Size */ public void setFontIconSize(int iconSize) { this.mFontIconSize = Utils.spToPx(getContext(), iconSize); if (mFontIconView != null) mFontIconView.setTextSize(iconSize); }
/** * Set the size of Text in sp * * @param textSize : Text Size */ public void setTextSize(int textSize) { this.mDefaultTextSize = Utils.spToPx(getContext(), textSize); if (mTextView != null) mTextView.setTextSize(textSize); }
private Typeface getTypeface(TypedArray ta) { if (ta.hasValue(R.styleable.FancyButtonsAttrs_android_fontFamily)) { int fontId = ta.getResourceId(R.styleable.FancyButtonsAttrs_android_fontFamily, 0); if (fontId != 0) return ResourcesCompat.getFont(getContext(), fontId); } if(ta.hasValue(R.styleable.FancyButtonsAttrs_fb_textFontRes)){ int fontId = ta.getResourceId(R.styleable.FancyButtonsAttrs_fb_textFontRes, 0); if (fontId != 0) return ResourcesCompat.getFont(getContext(), fontId); } return null; }
/** * Setup Text View * * @return : TextView */ private TextView setupTextView() { if (mText == null) { mText = "Fancy Button"; } TextView textView = new TextView(mContext); textView.setText(mText); textView.setGravity(mDefaultTextGravity); textView.setTextColor(mEnabled ? mDefaultTextColor : mDisabledTextColor); textView.setTextSize(Utils.pxToSp(getContext(), mDefaultTextSize)); textView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); if (!isInEditMode() && !mUseSystemFont) { textView.setTypeface(mTextTypeFace, textStyle); //we can pass null in first arg } return textView; }
fontIconView.setTextSize(Utils.pxToSp(getContext(), mFontIconSize)); fontIconView.setText(mFontIcon); fontIconView.setTypeface(mIconTypeFace); } else { fontIconView.setTextSize(Utils.pxToSp(getContext(), mFontIconSize)); fontIconView.setText("O");
/** * Set custom font for button Text * * @param fontId : Font id * Place your text fonts in font resources. * Eg. res/font/roboto.ttf or res/font/roboto.xml */ public void setCustomTextFont(@FontRes int fontId) { mTextTypeFace = ResourcesCompat.getFont(getContext(), fontId); if (mTextView == null) initializeFancyButton(); else mTextView.setTypeface(mTextTypeFace, textStyle); }