当前位置: 首页>>代码示例>>Java>>正文


Java Typeface.defaultFromStyle方法代码示例

本文整理汇总了Java中android.graphics.Typeface.defaultFromStyle方法的典型用法代码示例。如果您正苦于以下问题:Java Typeface.defaultFromStyle方法的具体用法?Java Typeface.defaultFromStyle怎么用?Java Typeface.defaultFromStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.graphics.Typeface的用法示例。


在下文中一共展示了Typeface.defaultFromStyle方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updatePaintTypeface

import android.graphics.Typeface; //导入方法依赖的package包/类
/**
 * Updates typeface setting for the given <var>paint</var> to the specified one.
 *
 * @param paint    The paint to be updated.
 * @param typeface The desired typeface. May be {@code null} to resolve instance of typeface
 *                 from the specified style.
 * @param style    The desired text style used to resolve proper instance of typeface.
 * @return {@code True} if paint's typeface setting has changed, {@code false} otherwise.
 * @see Paint#setTypeface(Typeface)
 */
public static boolean updatePaintTypeface(@NonNull Paint paint, @Nullable Typeface typeface, @TextStyle int style) {
	if (style > 0) {
		if (typeface == null) {
			typeface = Typeface.defaultFromStyle(style);
		} else {
			typeface = Typeface.create(typeface, style);
		}
		final int typefaceStyle = typeface != null ? typeface.getStyle() : 0;
		final int need = style & ~typefaceStyle;
		paint.setFakeBoldText((need & Typeface.BOLD) != 0);
		paint.setTextSkewX((need & Typeface.ITALIC) != 0 ? -0.25f : 0);
		paint.setTypeface(typeface);
	} else {
		paint.setFakeBoldText(false);
		paint.setTextSkewX(0);
		paint.setTypeface(typeface);
	}
	return true;
}
 
开发者ID:universum-studios,项目名称:android_ui,代码行数:30,代码来源:TextAppearance.java

示例2: onViewCreated

import android.graphics.Typeface; //导入方法依赖的package包/类
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    if(view!=null){
        caption.setText(getString(R.string.log_in_label));
        view.setBackgroundColor(ContextCompat.getColor(getContext(),R.color.color_log_in));
        for(TextInputEditText editText:views){
            if(editText.getId()==R.id.password_input_edit){
                final TextInputLayout inputLayout=ButterKnife.findById(view,R.id.password_input);
                Typeface boldTypeface = Typeface.defaultFromStyle(Typeface.BOLD);
                inputLayout.setTypeface(boldTypeface);
                editText.addTextChangedListener(new TextWatcherAdapter(){
                    @Override
                    public void afterTextChanged(Editable editable) {
                        inputLayout.setPasswordVisibilityToggleEnabled(editable.length()>0);
                    }
                });
            }
            editText.setOnFocusChangeListener((temp,hasFocus)->{
                if(!hasFocus){
                    boolean isEnabled=editText.getText().length()>0;
                    editText.setSelected(isEnabled);
                }
            });
        }
    }
}
 
开发者ID:vpaliyX,项目名称:LoginConcept,代码行数:28,代码来源:LogInFragment.java

示例3: onViewCreated

import android.graphics.Typeface; //导入方法依赖的package包/类
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    if(view!=null){
        view.setBackgroundColor(ContextCompat.getColor(getContext(),R.color.color_sign_up));
        caption.setText(getString(R.string.sign_up_label));
        for(TextInputEditText editText:views){
            if(editText.getId()==R.id.password_input_edit){
                final TextInputLayout inputLayout= ButterKnife.findById(view,R.id.password_input);
                final TextInputLayout confirmLayout=ButterKnife.findById(view,R.id.confirm_password);
                Typeface boldTypeface = Typeface.defaultFromStyle(Typeface.BOLD);
                inputLayout.setTypeface(boldTypeface);
                confirmLayout.setTypeface(boldTypeface);
                editText.addTextChangedListener(new TextWatcherAdapter(){
                    @Override
                    public void afterTextChanged(Editable editable) {
                        inputLayout.setPasswordVisibilityToggleEnabled(editable.length()>0);
                    }
                });
            }
            editText.setOnFocusChangeListener((temp,hasFocus)->{
                if(!hasFocus){
                    boolean isEnabled=editText.getText().length()>0;
                    editText.setSelected(isEnabled);
                }
            });
        }
        caption.setVerticalText(true);
        foldStuff();
        caption.setTranslationX(getTextPadding());
    }
}
 
开发者ID:vpaliyX,项目名称:LoginConcept,代码行数:33,代码来源:SignUpFragment.java

示例4: getTypeface

import android.graphics.Typeface; //导入方法依赖的package包/类
static Typeface getTypeface(CssStyleDeclaration style) {
  int flags = getTextStyle(style);
  if (!style.isSet(CssProperty.FONT_FAMILY)) {
    return Typeface.defaultFromStyle(flags);
  }
  return Typeface.create(getFontFamilyName(style), flags);
}
 
开发者ID:stefanhaustein,项目名称:nativehtml,代码行数:8,代码来源:AndroidCss.java

示例5: setSwitchTypeface

import android.graphics.Typeface; //导入方法依赖的package包/类
public void setSwitchTypeface(Typeface tf, int style) {
    boolean z = false;
    if (style > 0) {
        int typefaceStyle;
        float f;
        if (tf == null) {
            tf = Typeface.defaultFromStyle(style);
        } else {
            tf = Typeface.create(tf, style);
        }
        setSwitchTypeface(tf);
        if (tf != null) {
            typefaceStyle = tf.getStyle();
        } else {
            typefaceStyle = 0;
        }
        int need = style & (typefaceStyle ^ -1);
        TextPaint textPaint = this.mTextPaint;
        if ((need & 1) != 0) {
            z = true;
        }
        textPaint.setFakeBoldText(z);
        textPaint = this.mTextPaint;
        if ((need & 2) != 0) {
            f = -0.25f;
        } else {
            f = 0.0f;
        }
        textPaint.setTextSkewX(f);
        return;
    }
    this.mTextPaint.setFakeBoldText(false);
    this.mTextPaint.setTextSkewX(0.0f);
    setSwitchTypeface(tf);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:36,代码来源:SwitchCompat.java

示例6: getTypeface

import android.graphics.Typeface; //导入方法依赖的package包/类
/**
 * Returns a derivative of a given Typeface with a different style.
 */
public static Typeface getTypeface(Typeface typeface, int style) {
  if (typeface == null) {
    return Typeface.defaultFromStyle(style);
  }

  Typeface[] cache = TYPEFACE_CACHE.get(typeface);
  if (cache == null) {
    // This should not happen because all Typefaces are coming from TypefaceCache,
    // and thus should be registered in TYPEFACE_CACHE.
    // If we get here, it's a bug and one of the 2 scenarios happened:
    // a) TypefaceCache created a Typeface and didn't put it into TYPEFACE_CACHE.
    // b) someone else created a Typeface bypassing TypefaceCache so it's not registered here.
    //
    // If it's not registered, we can just register it manually for consistency, and so that
    // next time someone requests a un unknown Typeface, it's already cached and we don't create
    // extra copies.
    cache = new Typeface[MAX_STYLES];
    cache[typeface.getStyle()] = typeface;
  } else if (cache[style] != null) {
    // return cached value.
    return cache[style];
  }

  typeface = Typeface.create(typeface, style);
  cache[style] = typeface;
  TYPEFACE_CACHE.put(typeface, cache);
  return typeface;
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:32,代码来源:TypefaceCache.java

示例7: KeyVisualAttributes

import android.graphics.Typeface; //导入方法依赖的package包/类
private KeyVisualAttributes(@NonNull final TypedArray keyAttr) {
    if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyTypeface)) {
        mTypeface = Typeface.defaultFromStyle(
                keyAttr.getInt(R.styleable.Keyboard_Key_keyTypeface, Typeface.NORMAL));
    } else {
        mTypeface = null;
    }

    mLetterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLetterSize);
    mLetterSize = ResourceUtils.getDimensionPixelSize(keyAttr,
            R.styleable.Keyboard_Key_keyLetterSize);
    mLabelRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLabelSize);
    mLabelSize = ResourceUtils.getDimensionPixelSize(keyAttr,
            R.styleable.Keyboard_Key_keyLabelSize);
    mLargeLetterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLargeLetterRatio);
    mHintLetterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLetterRatio);
    mShiftedLetterHintRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyShiftedLetterHintRatio);
    mHintLabelRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLabelRatio);
    mPreviewTextRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyPreviewTextRatio);

    mTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyTextColor, 0);
    mTextInactivatedColor = keyAttr.getColor(
            R.styleable.Keyboard_Key_keyTextInactivatedColor, 0);
    mTextShadowColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyTextShadowColor, 0);
    mFunctionalTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_functionalTextColor, 0);
    mHintLetterColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyHintLetterColor, 0);
    mHintLabelColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyHintLabelColor, 0);
    mShiftedLetterHintInactivatedColor = keyAttr.getColor(
            R.styleable.Keyboard_Key_keyShiftedLetterHintInactivatedColor, 0);
    mShiftedLetterHintActivatedColor = keyAttr.getColor(
            R.styleable.Keyboard_Key_keyShiftedLetterHintActivatedColor, 0);
    mPreviewTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyPreviewTextColor, 0);

    mHintLabelVerticalAdjustment = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLabelVerticalAdjustment, 0.0f);
    mLabelOffCenterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLabelOffCenterRatio, 0.0f);
    mHintLabelOffCenterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLabelOffCenterRatio, 0.0f);
}
 
开发者ID:rkkr,项目名称:simple-keyboard,代码行数:48,代码来源:KeyVisualAttributes.java

示例8: drawColorBars

import android.graphics.Typeface; //导入方法依赖的package包/类
/**
 * Draw color bars with text labels.
 */
private void drawColorBars(Surface surface) {
    Canvas canvas = surface.lockCanvas(null);
    try {
        // TODO: if the device is in portrait, draw the color bars horizontally.  Right
        // now this only looks good in landscape.
        int width = canvas.getWidth();
        int height = canvas.getHeight();
        int least = Math.min(width, height);

        Log.d(TAG, "Drawing color bars at " + width + "x" + height);

        Paint textPaint = new Paint();
        Typeface typeface = Typeface.defaultFromStyle(Typeface.NORMAL);
        textPaint.setTypeface(typeface);
        textPaint.setTextSize(least / 20);
        textPaint.setAntiAlias(true);

        Paint rectPaint = new Paint();
        for (int i = 0; i < 8; i++) {
            int color = 0xff000000;
            if ((i & 0x01) != 0) {
                color |= 0x00ff0000;
            }
            if ((i & 0x02) != 0) {
                color |= 0x0000ff00;
            }
            if ((i & 0x04) != 0) {
                color |= 0x000000ff;
            }
            rectPaint.setColor(color);

            float sliceWidth = width / 8;
            canvas.drawRect(sliceWidth * i, 0, sliceWidth * (i+1), height, rectPaint);
        }
        rectPaint.setColor(0x80808080);     // ARGB 50/50 grey (non-premul)
        float sliceHeight = height / 8;
        int posn = 6;
        canvas.drawRect(0, sliceHeight * posn, width, sliceHeight * (posn+1), rectPaint);

        // Draw the labels last so they're on top of everything.
        for (int i = 0; i < 8; i++) {
            drawOutlineText(canvas, textPaint, COLOR_NAMES[i],
                    (width / 8) * i + 4, (height / 8) * ((i & 1) + 1));
        }
    } finally {
        surface.unlockCanvasAndPost(canvas);
    }
}
 
开发者ID:AndyZhu1991,项目名称:grafika,代码行数:52,代码来源:ColorBarActivity.java

示例9: KeyVisualAttributes

import android.graphics.Typeface; //导入方法依赖的package包/类
private KeyVisualAttributes(@Nonnull final TypedArray keyAttr) {
    if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyTypeface)) {
        mTypeface = Typeface.defaultFromStyle(
                keyAttr.getInt(R.styleable.Keyboard_Key_keyTypeface, Typeface.NORMAL));
    } else {
        mTypeface = null;
    }

    mLetterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLetterSize);
    mLetterSize = ResourceUtils.getDimensionPixelSize(keyAttr,
            R.styleable.Keyboard_Key_keyLetterSize);
    mLabelRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLabelSize);
    mLabelSize = ResourceUtils.getDimensionPixelSize(keyAttr,
            R.styleable.Keyboard_Key_keyLabelSize);
    mLargeLetterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLargeLetterRatio);
    mHintLetterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLetterRatio);
    mShiftedLetterHintRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyShiftedLetterHintRatio);
    mHintLabelRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLabelRatio);
    mPreviewTextRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyPreviewTextRatio);

    mTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyTextColor, 0);
    mTextInactivatedColor = keyAttr.getColor(
            R.styleable.Keyboard_Key_keyTextInactivatedColor, 0);
    mTextShadowColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyTextShadowColor, 0);
    mFunctionalTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_functionalTextColor, 0);
    mHintLetterColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyHintLetterColor, 0);
    mHintLabelColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyHintLabelColor, 0);
    mShiftedLetterHintInactivatedColor = keyAttr.getColor(
            R.styleable.Keyboard_Key_keyShiftedLetterHintInactivatedColor, 0);
    mShiftedLetterHintActivatedColor = keyAttr.getColor(
            R.styleable.Keyboard_Key_keyShiftedLetterHintActivatedColor, 0);
    mPreviewTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyPreviewTextColor, 0);

    mHintLabelVerticalAdjustment = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLabelVerticalAdjustment, 0.0f);
    mLabelOffCenterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLabelOffCenterRatio, 0.0f);
    mHintLabelOffCenterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLabelOffCenterRatio, 0.0f);
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:48,代码来源:KeyVisualAttributes.java


注:本文中的android.graphics.Typeface.defaultFromStyle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。