Java Code Examples for android.text.TextPaint.setColor()

The following are Jave code examples for showing how to use setColor() of the android.text.TextPaint class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Demos   File: CustomTextView.java   Source Code and License Vote up 8 votes
/**
 * 绘制多行居中文本(方式1)
 *
 * @param canvas 画布
 */
private void drawCenterMultiText1(Canvas canvas) {
    String text = "ABC";

    // 画笔
    TextPaint textPaint = new TextPaint();
    textPaint.setAntiAlias(true);
    textPaint.setColor(Color.GRAY);

    // 设置宽度超过50dp时换行
    StaticLayout staticLayout = new StaticLayout(text, textPaint, dp2px(50),
            Layout.Alignment.ALIGN_CENTER, 1, 0, false);
    canvas.save();
    // StaticLayout默认从(0,0)点开始绘制
    // 如果需要调整位置,只能在绘制之前移动Canvas的起始坐标
    canvas.translate(-staticLayout.getWidth() / 2, -staticLayout.getHeight() / 2);
    staticLayout.draw(canvas);
    canvas.restore();
}
 
Example 2
Project: SimpleUILauncher   File: PendingAppWidgetHostView.java   Source Code and License Vote up 6 votes
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public PendingAppWidgetHostView(Context context, LauncherAppWidgetInfo info,
        boolean disabledForSafeMode) {
    super(new ContextThemeWrapper(context, R.style.WidgetContainerTheme));

    mLauncher = Launcher.getLauncher(context);
    mInfo = info;
    mStartState = info.restoreStatus;
    mIconLookupIntent = new Intent().setComponent(info.providerName);
    mDisabledForSafeMode = disabledForSafeMode;

    mPaint = new TextPaint();
    mPaint.setColor(0xFFFFFFFF);
    mPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX,
            mLauncher.getDeviceProfile().iconTextSizePx, getResources().getDisplayMetrics()));
    setBackgroundResource(R.drawable.quantum_panel_dark);
    setWillNotDraw(false);

    if (Utilities.ATLEAST_LOLLIPOP) {
        setElevation(getResources().getDimension(R.dimen.pending_widget_elevation));
    }
}
 
Example 3
Project: PlusGram   File: AboutLinkCell.java   Source Code and License Vote up 6 votes
public AboutLinkCell(Context context) {
    super(context);

    textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    textPaint.setTextSize(AndroidUtilities.dp(16));
    textPaint.setColor(0xff000000);
    textPaint.linkColor = Theme.MSG_LINK_TEXT_COLOR;
    textPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));

    urlPaint = new Paint();
    urlPaint.setColor(Theme.MSG_LINK_SELECT_BACKGROUND_COLOR);
    urlPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));

    imageView = new ImageView(context);
    imageView.setScaleType(ImageView.ScaleType.CENTER);
    addView(imageView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 16, 5, LocaleController.isRTL ? 16 : 0, 0));
    setWillNotDraw(false);
}
 
Example 4
Project: GitHub   File: PieChartRenderer.java   Source Code and License Vote up 5 votes
public PieChartRenderer(PieChart chart, ChartAnimator animator,
                        ViewPortHandler viewPortHandler) {
    super(animator, viewPortHandler);
    mChart = chart;

    mHolePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mHolePaint.setColor(Color.WHITE);
    mHolePaint.setStyle(Style.FILL);

    mTransparentCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTransparentCirclePaint.setColor(Color.WHITE);
    mTransparentCirclePaint.setStyle(Style.FILL);
    mTransparentCirclePaint.setAlpha(105);

    mCenterTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mCenterTextPaint.setColor(Color.BLACK);
    mCenterTextPaint.setTextSize(Utils.convertDpToPixel(12f));

    mValuePaint.setTextSize(Utils.convertDpToPixel(13f));
    mValuePaint.setColor(Color.WHITE);
    mValuePaint.setTextAlign(Align.CENTER);

    mEntryLabelsPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mEntryLabelsPaint.setColor(Color.WHITE);
    mEntryLabelsPaint.setTextAlign(Align.CENTER);
    mEntryLabelsPaint.setTextSize(Utils.convertDpToPixel(13f));

    mValueLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mValueLinePaint.setStyle(Style.STROKE);
}
 
Example 5
Project: baselibrary-master   File: AutoWrapTextView.java   Source Code and License Vote up 5 votes
private void initPaint()
{
    mTextPaint = new TextPaint();
    mTextPaint.setAntiAlias(true);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setColor(mTextColor);
    mTextPaint.setTextAlign(Paint.Align.LEFT);
}
 
Example 6
Project: CornerLabelView   File: CornerLabelView.java   Source Code and License Vote up 5 votes
private void init() {
    mPath = new Path();

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setColor(bgColor);

    mTextPaint = new TextPaint();
    mTextPaint.setAntiAlias(true);
    mTextPaint.setColor(textColor);
    mTextPaint.setTextSize(textSize);
}
 
Example 7
Project: AdvancedTextView   File: SelectableTextView.java   Source Code and License Vote up 5 votes
/**
 * 重绘文字,两端对齐
 *
 * @param canvas
 */
private void drawTextWithJustify(Canvas canvas) {
    // 文字画笔
    TextPaint textPaint = getPaint();
    textPaint.setColor(getCurrentTextColor());
    textPaint.drawableState = getDrawableState();

    String text_str = getText().toString();
    // 当前所在行的Y向偏移
    int currentLineOffsetY = getPaddingTop();
    currentLineOffsetY += getTextSize();

    Layout layout = getLayout();

    //循环每一行,绘制文字
    for (int i = 0; i < layout.getLineCount(); i++) {
        int lineStart = layout.getLineStart(i);
        int lineEnd = layout.getLineEnd(i);
        //获取到TextView每行中的内容
        String line_str = text_str.substring(lineStart, lineEnd);
        // 获取每行字符串的宽度(不包括字符间距)
        float desiredWidth = StaticLayout.getDesiredWidth(text_str, lineStart, lineEnd, getPaint());

        if (isLineNeedJustify(line_str)) {
            //最后一行不需要重绘
            if (i == layout.getLineCount() - 1) {
                canvas.drawText(line_str, getPaddingLeft(), currentLineOffsetY, textPaint);
            } else {
                drawJustifyTextForLine(canvas, line_str, desiredWidth, currentLineOffsetY);
            }
        } else {
            canvas.drawText(line_str, getPaddingLeft(), currentLineOffsetY, textPaint);
        }
        //更新行Y向偏移
        currentLineOffsetY += getLineHeight();
    }
}
 
Example 8
Project: PlusGram   File: SecretPhotoViewer.java   Source Code and License Vote up 5 votes
public SecretDeleteTimer(Context context) {
    super(context);
    setWillNotDraw(false);

    infoPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    infoPaint.setTextSize(AndroidUtilities.dp(15));
    infoPaint.setColor(0xffffffff);

    deleteProgressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    deleteProgressPaint.setColor(0xffe6e6e6);

    drawable = getResources().getDrawable(R.drawable.circle1);
}
 
Example 9
Project: NovelReader   File: PageLoader.java   Source Code and License Vote up 5 votes
private void initPaint(){
    //绘制提示的画笔
    mTipPaint = new Paint();
    mTipPaint.setColor(mTextColor);
    mTipPaint.setTextAlign(Paint.Align.LEFT);//绘制的起始点
    mTipPaint.setTextSize(ScreenUtils.spToPx(DEFAULT_TIP_SIZE));//Tip默认的字体大小
    mTipPaint.setAntiAlias(true);
    mTipPaint.setSubpixelText(true);

    //绘制页面内容的画笔
    mTextPaint = new TextPaint();
    mTextPaint.setColor(mTextColor);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setAntiAlias(true);

    //绘制标题的画笔
    mTitlePaint = new TextPaint();
    mTitlePaint.setColor(mTextColor);
    mTitlePaint.setTextSize(mTitleSize);
    mTitlePaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mTitlePaint.setTypeface(Typeface.DEFAULT_BOLD);
    mTitlePaint.setAntiAlias(true);

    //绘制背景的画笔
    mBgPaint = new Paint();
    mBgPaint.setColor(mPageBg);

    mBatteryPaint = new Paint();
    mBatteryPaint.setAntiAlias(true);
    mBatteryPaint.setDither(true);
    if (isNightMode){
        mBatteryPaint.setColor(Color.WHITE);
    }
    else {
        mBatteryPaint.setColor(Color.BLACK);
    }
}
 
Example 10
Project: TextBuilder   File: CustomSpan.java   Source Code and License Vote up 5 votes
@Override public void updateDrawState(final TextPaint ds) {
  if (isBold) {
    ds.setTypeface(Typeface.DEFAULT_BOLD);
  }

  ds.setUnderlineText(shouldUnderline);

  if (textColor != null) {
    ds.setColor(textColor);
  }
}
 
Example 11
Project: GitHub   File: BarChart.java   Source Code and License Vote up 5 votes
private void init(Context context) {
    final float density = context.getResources().getDisplayMetrics().density;

    mPaints[0] = new Paint();
    mPaints[0].setColor(0xfff5d391);

    mPaints[1] = new Paint();
    mPaints[1].setColor(0xffa9e8fe);

    mPaints[2] = new Paint();
    mPaints[2].setColor(0xffe9969c);

    mPaints[3] = new Paint();
    mPaints[3].setColor(0xffb5d951);

    mTextPaint = new TextPaint();
    mTextPaint.setColor(0xff555555);
    mTextPaint.setAntiAlias(true);
    mTextPaint.setTextSize(density * 12);

    mColumnHeight = (int)(density * 20);
    mColumnPadding = (int)(density * 2);
    mSectionPadding = (int)(density * 24);
    mDividerHeight = (int)(density * 2);
    mTextPadding = (int)(density * 4);

    for (int i = 0; i < SECTION_COUNT; i++) {
        mSections[i] = new Section();
    }
}
 
Example 12
Project: Rxjava2.0Demo   File: NineGridViewWrapper.java   Source Code and License Vote up 5 votes
public NineGridViewWrapper(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    //转化单位
    textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, textSize, getContext().getResources().getDisplayMetrics());

    textPaint = new TextPaint();
    textPaint.setTextAlign(Paint.Align.CENTER);  //文字居中对齐
    textPaint.setAntiAlias(true);                //抗锯齿
    textPaint.setTextSize(textSize);             //设置文字大小
    textPaint.setColor(textColor);               //设置文字颜色
}
 
Example 13
Project: TextReader   File: BookContentTextView.java   Source Code and License Vote up 4 votes
@Override
public void updateDrawState(TextPaint ds) {
    super.updateDrawState(ds);
    ds.setColor(ContextCompat.getColor(getContext(), R.color.light_coffee));
    ds.setUnderlineText(false);
}
 
Example 14
Project: Quran   File: JuzView.java   Source Code and License Vote up 4 votes
public JuzView(Context context, int type, String overlayText) {
  final Resources resources = context.getResources();
  final int circleColor = ContextCompat.getColor(context, R.color.accent_color);
  final int circleBackground = ContextCompat.getColor(context, R.color.accent_color_dark);

  mCirclePaint = new Paint();
  mCirclePaint.setStyle(Paint.Style.FILL);
  mCirclePaint.setColor(circleColor);
  mCirclePaint.setAntiAlias(true);

  mCircleBackgroundPaint = new Paint();
  mCircleBackgroundPaint.setStyle(Paint.Style.FILL);
  mCircleBackgroundPaint.setColor(circleBackground);
  mCircleBackgroundPaint.setAntiAlias(true);

  mOverlayText = overlayText;
  if (!TextUtils.isEmpty(mOverlayText)) {
    final int textColor = ContextCompat.getColor(context, R.color.header_background);
    final int textSize =
        resources.getDimensionPixelSize(R.dimen.juz_overlay_text_size);
    mOverlayTextPaint = new TextPaint();
    mOverlayTextPaint.setAntiAlias(true);
    mOverlayTextPaint.setColor(textColor);
    mOverlayTextPaint.setTextSize(textSize);
    mOverlayTextPaint.setTextAlign(Paint.Align.CENTER);

    final float textHeight =
        mOverlayTextPaint.descent() - mOverlayTextPaint.ascent();
    mTextOffset = (textHeight / 2) - mOverlayTextPaint.descent();
  }

  final int percentage;
  switch (type) {
    case TYPE_JUZ:
      percentage = 100;
      break;
    case TYPE_THREE_QUARTERS:
      percentage = 75;
      break;
    case TYPE_HALF:
      percentage = 50;
      break;
    case TYPE_QUARTER:
      percentage = 25;
      break;
    default:
      percentage = 0;
  }
  mPercentage = percentage;
}
 
Example 15
Project: GitHub   File: AnimationAdapter.java   Source Code and License Vote up 4 votes
@Override
public void updateDrawState(TextPaint ds) {
    ds.setColor(Utils.getContext().getResources().getColor(R.color.clickspan_color));
    ds.setUnderlineText(true);
}
 
Example 16
Project: RLibrary   File: RExItemDecoration.java   Source Code and License Vote up 4 votes
/**
 * 在底部左边绘制一个偏移距离的线
 */
protected void drawLeftBottomLine(Canvas canvas, TextPaint paint, View itemView, Rect offsetRect, int itemCount, int position) {
    paint.setColor(getOffsetPaintColor(itemView.getContext()));
    offsetRect.set(0, itemView.getBottom(), getLeftOffset(itemView.getContext()), itemView.getBottom() + offsetRect.bottom);
    canvas.drawRect(offsetRect, paint);
}
 
Example 17
Project: IconDotTextView   File: TextConfig.java   Source Code and License Vote up 4 votes
private void initPaint() {
    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setColor(DEFAULT_COLOR);
    mTextPaint.setTextSize(mSize);
}
 
Example 18
Project: airgram   File: URLSpanUserMention.java   Source Code and License Vote up 4 votes
@Override
public void updateDrawState(TextPaint ds) {
    super.updateDrawState(ds);
    ds.setColor(Theme.MSG_LINK_TEXT_COLOR);
    ds.setUnderlineText(false);
}
 
Example 19
Project: RLibrary   File: RExItemDecoration.java   Source Code and License Vote up 4 votes
/**
 * 简单的在底部绘制一根线
 */
protected void drawBottomLine(Canvas canvas, TextPaint paint, View itemView, Rect offsetRect, int itemCount, int position) {
    paint.setColor(getPaintColor(itemView.getContext()));
    offsetRect.set(0, itemView.getBottom(), itemView.getRight(), itemView.getBottom() + offsetRect.bottom);
    canvas.drawRect(offsetRect, paint);
}
 
Example 20
Project: mvvm-template   File: LinkSpan.java   Source Code and License Vote up 4 votes
@Override
public void updateDrawState(TextPaint ds) {
    super.updateDrawState(ds);
    ds.setColor(color);
    ds.setUnderlineText(false);
}