当前位置: 首页>>代码示例>>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;未经允许,请勿转载。