當前位置: 首頁>>代碼示例>>Java>>正文


Java TextPaint.getTypeface方法代碼示例

本文整理匯總了Java中android.text.TextPaint.getTypeface方法的典型用法代碼示例。如果您正苦於以下問題:Java TextPaint.getTypeface方法的具體用法?Java TextPaint.getTypeface怎麽用?Java TextPaint.getTypeface使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.text.TextPaint的用法示例。


在下文中一共展示了TextPaint.getTypeface方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getTextWidth

import android.text.TextPaint; //導入方法依賴的package包/類
private static int getTextWidth(@Nullable final CharSequence text, final TextPaint paint) {
    if (TextUtils.isEmpty(text)) {
        return 0;
    }
    final int length = text.length();
    final float[] widths = new float[length];
    final int count;
    final Typeface savedTypeface = paint.getTypeface();
    try {
        paint.setTypeface(getTextTypeface(text));
        count = paint.getTextWidths(text, 0, length, widths);
    } finally {
        paint.setTypeface(savedTypeface);
    }
    int width = 0;
    for (int i = 0; i < count; i++) {
        width += Math.round(widths[i] + 0.5f);
    }
    return width;
}
 
開發者ID:sergeychilingaryan,項目名稱:AOSP-Kayboard-7.1.2,代碼行數:21,代碼來源:SuggestionStripLayoutHelper.java

示例2: apply

import android.text.TextPaint; //導入方法依賴的package包/類
private void apply(TextPaint paint) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }
    final int fakeStyle = oldStyle & ~typeface.getStyle();

    if ((fakeStyle & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fakeStyle & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(typeface);
}
 
開發者ID:suragch,項目名稱:mongol-library,代碼行數:21,代碼來源:MongolTypefaceSpan.java

示例3: updateTypeface

import android.text.TextPaint; //導入方法依賴的package包/類
private void updateTypeface(TextPaint ds) {
  Typeface typeface = ds.getTypeface();

  int oldStyle = (typeface == null) ? 0 : typeface.getStyle();
  int newStyle = getNewStyle(oldStyle);

  if (oldStyle == newStyle && mFontFamily == null) {
    // nothing to do
    return;
  }

  if (mFontFamily != null) {
    typeface = TypefaceCache.getTypeface(mFontFamily, newStyle);
  } else {
    typeface = TypefaceCache.getTypeface(typeface, newStyle);
  }

  ds.setTypeface(typeface);
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:20,代碼來源:FontStylingSpan.java

示例4: CandidateView

import android.text.TextPaint; //導入方法依賴的package包/類
/**
 * Construct a CandidateView for showing suggested words for completion.
 * @param context context
 */
public CandidateView(Context context) {
    super(context);
    mService = (QuranKeyboardIME) context;

    mSelectionHighlight = ContextCompat.getDrawable(context,
            android.R.drawable.list_selector_background);
    mSelectionHighlight.setState(new int[] {
            android.R.attr.state_enabled,
            android.R.attr.state_focused,
            android.R.attr.state_window_focused,
            android.R.attr.state_pressed
    });

    Resources r = context.getResources();
    
    setBackgroundColor(ContextCompat.getColor(context, R.color.candidate_background));
    
    mColorNormal = ContextCompat.getColor(context, R.color.candidate_normal);
    mColorRecommended = ContextCompat.getColor(context, R.color.candidate_recommended);
    mColorOther = ContextCompat.getColor(context, R.color.candidate_other);
    mVerticalPadding = r.getDimensionPixelSize(R.dimen.candidate_vertical_padding);

    mPaint = new TextPaint();
    mPaint.setColor(mColorNormal);
    mPaint.setAntiAlias(true);
    mPaint.setTextSize(r.getDimensionPixelSize(R.dimen.candidate_font_height));
    mPaint.setStrokeWidth(0);
    mDefaultTf = mPaint.getTypeface();
    mUthamniTf = mService.getUthmaniTypeFace();

    mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2,
                float distanceX, float distanceY) {
            mScrolled = true;
            int sx = getScrollX();
            sx += distanceX;
            if (sx < 0) {
                sx = 0;
            }
            if (sx + getWidth() > mTotalWidth) {                    
                sx -= distanceX;
            }
            mTargetScrollX = sx;
            scrollTo(sx, getScrollY());
            invalidate();
            return true;
        }
    });
    setHorizontalFadingEdgeEnabled(true);
    setWillNotDraw(false);
    setHorizontalScrollBarEnabled(false);
    setVerticalScrollBarEnabled(false);
}
 
開發者ID:cdjalel,項目名稱:QuranKeyboard,代碼行數:59,代碼來源:CandidateView.java


注:本文中的android.text.TextPaint.getTypeface方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。