/** * Set the default text size to the given value, interpreted as "scaled * pixel" units. This size is adjusted based on the current density and * user font size preference. * * @param size The scaled pixel size. * * @attr ref android.R.styleable#TextView_textSize */ public void setTextSize (float size){ mInputView.setTextSize(size); }
/** * Set the default text size to a given unit and value. See {@link * TypedValue} for the possible dimension units. * * @param unit The desired dimension unit. * @param size The desired size in the given units. * * @attr ref android.R.styleable#TextView_textSize */ public void setTextSize (int unit, float size){ mInputView.setTextSize(unit, size); }
@Override public void setTextSize(int unit, float size) { super.setTextSize(unit, size); adjustTextSize(); }
@Override public void setTextSize(float size) { super.setTextSize(size); adjustTextSize(); }
etContent.setBackgroundDrawable(null); etContent.setTextColor(0xff3b3b3b); etContent.setTextSize(TypedValue.COMPLEX_UNIT_SP, 21); etContent.setText(sp.getText()); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
etContent.setBackgroundDrawable(null); etContent.setTextColor(0xff3b3b3b); etContent.setTextSize(TypedValue.COMPLEX_UNIT_SP, 21); etContent.setText(sp.getText()); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
etContent.setBackgroundDrawable(null); etContent.setTextColor(0xff3b3b3b); etContent.setTextSize(TypedValue.COMPLEX_UNIT_SP, 21); etContent.setText(sp.getText()); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT);
etContent.setBackgroundDrawable(null); etContent.setTextColor(0xff3b3b3b); etContent.setTextSize(TypedValue.COMPLEX_UNIT_SP, 21); etContent.setText(sp.getText()); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT);
editText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); editText.setTypeface(typeface, 0); editText.setGravity(gravity);
mEdit.setSelection(mBuilder.getContentText().length()); mEdit.setTextColor(mBuilder.getContentTextColor()); mEdit.setTextSize(mBuilder.getContentTextSize()); mLeftBtn.setText(mBuilder.getLeftButtonText()); mLeftBtn.setTextColor(mBuilder.getLeftButtonTextColor());
editText.setLinkTextColor(linkColor); editText.setHighlightColor(highlightColor); editText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); editText.setLineSpacing(extraSpacing, spacingMultiplier); editText.setTypeface(typeface, textStyle);
private void adjustTextSize() { if (autoSizeText == AutoSizeTextMode.None || minTextSize <= 0 || maxTextSize <= 0 || getMeasuredWidth() == 0 || getMeasuredHeight() == 0) return; if (autoSizeStepPresets == null) initAutoSize(); availableSpaceRect.right = getMeasuredWidth() - getCompoundPaddingLeft() - getCompoundPaddingRight(); availableSpaceRect.bottom = getMeasuredHeight() - getCompoundPaddingBottom() - getCompoundPaddingTop(); super.setTextSize(TypedValue.COMPLEX_UNIT_PX, binarySearch(availableSpaceRect)); }
@Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { switch (view.getId()) { case R.id.color_group: mCurFocusText.setTextColor(Color.parseColor(TEXT_COLOR_TIPS_ARRAY[newVal])); break; case R.id.size_group: mCurFocusText.setTextSize(TypedValue.COMPLEX_UNIT_PX, Integer.parseInt(TEXT_SIZE_TIPS_ARRAY[newVal])); break; default: mCurFocusText.setTypeface(mTypefaces[newVal]); break; } } });
private View renderEditableCatName(final Car car) { final EditText editText = new EditText(getContext()); editText.setText(car.getName()); editText.setPadding(20, 10, 20, 10); editText.setTextSize(TEXT_SIZE); editText.setSingleLine(); editText.addTextChangedListener(new CarNameUpdater(car)); return editText; }
private void cloneEditText(EditText dstText, EditText srcText) { dstText.setText(srcText.getText()); dstText.setTextColor(srcText.getTextColors()); dstText.setTypeface(srcText.getTypeface()); dstText.setTextSize(TypedValue.COMPLEX_UNIT_PX, srcText.getTextSize()); } }
/** * 生成文本输入框 */ public EditText createEditText(String hint, int paddingTop) { EditText editText = (EditText) inflater.inflate(R.layout.rich_edittext, null); editText.setOnKeyListener(keyListener); editText.setTag(viewTagIndex++); editText.setPadding(editNormalPadding, paddingTop, editNormalPadding, paddingTop); editText.setHint(hint); //editText.setTextSize(rtTextSize); editText.setTextSize(TypedValue.COMPLEX_UNIT_PX, rtTextSize); editText.setTextColor(rtTextColor); editText.setLineSpacing(rtTextLineSpace, 1.0f); editText.setOnFocusChangeListener(focusListener); return editText; }
/** * 设置 edit 字体大小 * * @param editSizeSp * @return */ public MyOneLineView setEditSize(int editSizeSp) { editContent.setTextSize(editSizeSp); return this; } //----------------------下面是一些点击事件
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); EditText edit = (EditText) findViewById(R.id.edit); edit.setTextSize(20); edit.setText("Hello, world"); edit.measure(0, 0); int height = edit.getMeasuredHeight(); }
private void applyStyle() { setEnabled(mEnabled); mMessageEditText.setTextColor(mTextColor); mMessageEditText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize); EditTextUtil.setCursorDrawableColor(mMessageEditText, mCursorColor); EditTextUtil.setUnderlineColor(mMessageEditText, mUnderlineColor); applyTypeface(); ColorStateList list = getResources().getColorStateList(R.color.atlas_message_composer_attach_button); Drawable d = DrawableCompat.wrap(mAttachButton.getDrawable().mutate()); DrawableCompat.setTintList(d, list); mAttachButton.setImageDrawable(d); }
private void restoreTypography(CheckListView v, EditText returnView) { if (v.getEditText() != null) { returnView.setTypeface(v.getEditText().getTypeface()); returnView.setTextSize(0, v.getEditText().getTextSize()); returnView.setTextColor(v.getEditText().getTextColors()); returnView.setLinkTextColor(v.getEditText().getLinkTextColors()); } }