當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。