本文整理汇总了Java中android.widget.TextView.getTextSize方法的典型用法代码示例。如果您正苦于以下问题:Java TextView.getTextSize方法的具体用法?Java TextView.getTextSize怎么用?Java TextView.getTextSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.TextView
的用法示例。
在下文中一共展示了TextView.getTextSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onSharedElementStart
import android.widget.TextView; //导入方法依赖的package包/类
@Override
public void onSharedElementStart(List<String> sharedElementNames,
List<View> sharedElements,
List<View> sharedElementSnapshots) {
TextView author = getAuthor();
targetTextSize = author.getTextSize();
targetTextColors = author.getTextColors();
targetPadding = new Rect(author.getPaddingLeft(),
author.getPaddingTop(),
author.getPaddingRight(),
author.getPaddingBottom());
if (IntentUtil.hasAll(intent,
IntentUtil.TEXT_COLOR, IntentUtil.FONT_SIZE, IntentUtil.PADDING)) {
author.setTextColor(intent.getIntExtra(IntentUtil.TEXT_COLOR, Color.BLACK));
float textSize = intent.getFloatExtra(IntentUtil.FONT_SIZE, targetTextSize);
author.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
Rect padding = intent.getParcelableExtra(IntentUtil.PADDING);
author.setPadding(padding.left, padding.top, padding.right, padding.bottom);
}
}
示例2: recurseGroup
import android.widget.TextView; //导入方法依赖的package包/类
private static void recurseGroup(final ViewGroup viewGroup) {
for (int i = 0; i < viewGroup.getChildCount(); i++) {
View v = viewGroup.getChildAt(i);
if (v instanceof TextView) {
final TextView text = (TextView) v;
final String szText = text.getText().toString();
if (TITLE_TEXT.equals(szText)) {
TITLE_COLOR = text.getTextColors().getDefaultColor();
TITLE_SIZE = text.getTextSize();
} else if (CONTENT_TEXT.equals(szText)) {
CONTENT_COLOR = text.getTextColors().getDefaultColor();
CONTENT_SIZE = text.getTextSize();
}
if (TITLE_COLOR != null && CONTENT_COLOR != null) {
return;
}
}
if (v instanceof ViewGroup) {
recurseGroup((ViewGroup) viewGroup.getChildAt(i));
}
}
}
示例3: setCompoundDrawables
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 设置TextView上下左右的图片
*
* @param left
* @param top
* @param right
* @param bottom
* @return ToastBar
*/
public ToastBar setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom) {
TextView message = (TextView) snackbar.getView().findViewById(R.id.snackbar_text);
LinearLayout.LayoutParams paramsMessage = (LinearLayout.LayoutParams) message.getLayoutParams();
paramsMessage = new LinearLayout.LayoutParams(paramsMessage.width, paramsMessage.height, 0.0f);
message.setLayoutParams(paramsMessage);
message.setCompoundDrawablePadding(message.getPaddingLeft());
int textSize = (int) message.getTextSize();
if (left != null) {
left.setBounds(0, 0, textSize, textSize);
}
if (right != null) {
right.setBounds(0, 0, textSize, textSize);
}
message.setCompoundDrawables(left, top, right, bottom);
LinearLayout.LayoutParams paramsSpace = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);
((Snackbar.SnackbarLayout) snackbar.getView()).addView(new Space(snackbar.getView().getContext()), 1, paramsSpace);
return this;
}
示例4: updateTextViewParams
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 对控件进行参数的更新操作
*
* @param tv
*/
private void updateTextViewParams(TextView tv, float rotation, float scale) {
for (int i = 0; i < listTvParams.size(); i++) {
TextViewParams param = new TextViewParams();
if (tv.getTag().toString().equals(listTvParams.get(i).getTag())) {
param.setRotation(rotation);
param.setTextSize((float) (tv.getTextSize() / scaleTimes));
param.setMidPoint(getViewMidPoint(tv));
param.setScale(scale);
textSize = tv.getTextSize() / 2;
param.setWidth(tv.getWidth());
param.setHeight(tv.getHeight());
param.setX(tv.getX());
param.setY(tv.getY());
param.setTag(listTvParams.get(i).getTag());
param.setContent(tv.getText().toString());
param.setTextColor(color);
listTvParams.set(i, param);
return;
}
}
}
示例5: leftAndRightDrawable
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 设置TextView(@+id/snackbar_text)左右两侧的图片
*
* @param leftDrawable
* @param rightDrawable
* @return
*/
public SnackbarUtils leftAndRightDrawable(@Nullable Drawable leftDrawable, @Nullable Drawable rightDrawable) {
if (getSnackbar() != null) {
TextView message = (TextView) getSnackbar().getView().findViewById(R.id.snackbar_text);
LinearLayout.LayoutParams paramsMessage = (LinearLayout.LayoutParams) message.getLayoutParams();
paramsMessage = new LinearLayout.LayoutParams(paramsMessage.width, paramsMessage.height, 0.0f);
message.setLayoutParams(paramsMessage);
message.setCompoundDrawablePadding(message.getPaddingLeft());
int textSize = (int) message.getTextSize();
if (leftDrawable != null) {
leftDrawable.setBounds(0, 0, textSize, textSize);
}
if (rightDrawable != null) {
rightDrawable.setBounds(0, 0, textSize, textSize);
}
message.setCompoundDrawables(leftDrawable, null, rightDrawable, null);
LinearLayout.LayoutParams paramsSpace = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);
((Snackbar.SnackbarLayout) getSnackbar().getView()).addView(new Space(getSnackbar().getView().getContext()), 1, paramsSpace);
}
return this;
}
示例6: getEmotionContent
import android.widget.TextView; //导入方法依赖的package包/类
public static SpannableString getEmotionContent(int emotion_map_type, final Context context, final TextView tv, String source) {
SpannableString spannableString = new SpannableString(source);
Resources res = context.getResources();
String regexEmotion = "\\[([\u4e00-\u9fa5\\w])+\\]";
Pattern patternEmotion = Pattern.compile(regexEmotion);
Matcher matcherEmotion = patternEmotion.matcher(spannableString);
while (matcherEmotion.find()) {
// 获取匹配到的具体字符
String key = matcherEmotion.group();
// 匹配字符串的开始位置
int start = matcherEmotion.start();
// 利用表情名字获取到对应的图片
Integer imgRes = EmotionUtils.getImgByName(emotion_map_type, key);
if (imgRes != -1) {//-1代表纯文本,没有图片
// 压缩表情图片
int size = (int) tv.getTextSize() * 13 / 10;
Bitmap bitmap = BitmapFactory.decodeResource(res, imgRes);
Bitmap scaleBitmap = Bitmap.createScaledBitmap(bitmap, size, size, true);
// ImageSpan span = new ImageSpan(context, scaleBitmap);
final CenterAlignImageSpan span = new CenterAlignImageSpan(context, scaleBitmap, ImageSpan.ALIGN_BASELINE);
spannableString.setSpan(span, start, start + key.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return spannableString;
}
示例7: adjustTextSize
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 使文字大小适应frame
*
* @param view
*/
public static void adjustTextSize(TextView view) {
final Context context = view.getContext();
float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
TextPaint paint = new TextPaint();
int maxLines = getMaxLines(view);
float minTextSize = scaledDensity * DEFAULT_MIN_TEXT_SIZE;
float maxTextSize = view.getTextSize();
float precision = DEFAULT_PRECISION;
adjustTextSize(view, paint, minTextSize, maxTextSize, maxLines, precision);
}
示例8: findMaxTextSizeIndex
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 找到字号最大的textView
*
* @param textViews
* @return
*/
private static int findMaxTextSizeIndex(List<TextView> textViews) {
float max = Integer.MIN_VALUE;
int maxIndex = Integer.MIN_VALUE;
int index = 0;
for (TextView textView : textViews) {
if (max < textView.getTextSize()) {
max = textView.getTextSize();
maxIndex = index;
}
index++;
}
return maxIndex;
}
示例9: scaleProcessTextSize
import android.widget.TextView; //导入方法依赖的package包/类
/**
* Scale the textview's font size
*
* @param view
*/
public static void scaleProcessTextSize(TextView view) {
if (view == null)
return;
Object isScale = view.getTag(R.id.is_scale_fontsize_tag);
if (isScale instanceof Boolean) {
if ((Boolean) isScale == true) {
return;
}
}
float size = view.getTextSize();
size *= sScale;
// Size's unit use pixel,so param unit use TypedValue.COMPLEX_UNIT_PX.
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
}
示例10: get
import android.widget.TextView; //导入方法依赖的package包/类
@Override
public Float get(TextView textView) {
return textView.getTextSize();
}
示例11: init
import android.widget.TextView; //导入方法依赖的package包/类
private void init() {
mSolidColor = 0;
mSelectionDivider = getResources().getDrawable(R.drawable.numberpicker_selection_divider);
mSelectionDividerHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDER_HEIGHT, getResources().getDisplayMetrics());
mSelectionDividersDistance = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDERS_DISTANCE, getResources().getDisplayMetrics());
mMinHeight = SIZE_UNSPECIFIED;
mMaxHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 180, getResources().getDisplayMetrics());
if (mMinHeight != SIZE_UNSPECIFIED && mMaxHeight != SIZE_UNSPECIFIED && mMinHeight > mMaxHeight) {
throw new IllegalArgumentException("minHeight > maxHeight");
}
mMinWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 64, getResources().getDisplayMetrics());
mMaxWidth = SIZE_UNSPECIFIED;
if (mMinWidth != SIZE_UNSPECIFIED && mMaxWidth != SIZE_UNSPECIFIED && mMinWidth > mMaxWidth) {
throw new IllegalArgumentException("minWidth > maxWidth");
}
mComputeMaxWidth = (mMaxWidth == SIZE_UNSPECIFIED);
mVirtualButtonPressedDrawable = getResources().getDrawable(R.drawable.item_background_holo_light);
mPressedStateHelper = new PressedStateHelper();
setWillNotDraw(false);
mInputText = new TextView(getContext());
addView(mInputText);
mInputText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
mInputText.setGravity(Gravity.CENTER);
mInputText.setSingleLine(true);
mInputText.setBackgroundResource(0);
mInputText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
ViewConfiguration configuration = ViewConfiguration.get(getContext());
mTouchSlop = configuration.getScaledTouchSlop();
mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity() / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT;
mTextSize = (int) mInputText.getTextSize();
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setTextAlign(Align.CENTER);
paint.setTextSize(mTextSize);
paint.setTypeface(mInputText.getTypeface());
ColorStateList colors = mInputText.getTextColors();
int color = colors.getColorForState(ENABLED_STATE_SET, Color.WHITE);
paint.setColor(color);
mSelectorWheelPaint = paint;
mFlingScroller = new Scroller(getContext(), null, true);
mAdjustScroller = new Scroller(getContext(), new DecelerateInterpolator(2.5f));
updateInputTextView();
}
示例12: testScaleTimes
import android.widget.TextView; //导入方法依赖的package包/类
private void testScaleTimes() {
TextView tv = new TextView(context);
tv.setTextSize(1);
scaleTimes = tv.getTextSize();
// Log.e("HHHHHHH","缩放倍数"+scaleTimes);
}
示例13: init
import android.widget.TextView; //导入方法依赖的package包/类
private void init() {
mSolidColor = 0;
mSelectionDivider = getResources().getDrawable(R.drawable.numberpicker_selection_divider);
mSelectionDividerHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDER_HEIGHT, getResources().getDisplayMetrics());
mSelectionDividersDistance = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDERS_DISTANCE, getResources().getDisplayMetrics());
mMinHeight = SIZE_UNSPECIFIED;
mMaxHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 180, getResources().getDisplayMetrics());
if (mMinHeight != SIZE_UNSPECIFIED && mMaxHeight != SIZE_UNSPECIFIED && mMinHeight > mMaxHeight) {
throw new IllegalArgumentException("minHeight > maxHeight");
}
mMinWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 64, getResources().getDisplayMetrics());
mMaxWidth = SIZE_UNSPECIFIED;
if (mMinWidth != SIZE_UNSPECIFIED && mMaxWidth != SIZE_UNSPECIFIED && mMinWidth > mMaxWidth) {
throw new IllegalArgumentException("minWidth > maxWidth");
}
mComputeMaxWidth = (mMaxWidth == SIZE_UNSPECIFIED);
mVirtualButtonPressedDrawable = getResources().getDrawable(R.drawable.item_background_holo_light);
mPressedStateHelper = new PressedStateHelper();
setWillNotDraw(false);
mInputText = new TextView(getContext());
addView(mInputText);
mInputText.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
mInputText.setGravity(Gravity.CENTER);
mInputText.setSingleLine(true);
mInputText.setBackgroundResource(0);
mInputText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
ViewConfiguration configuration = ViewConfiguration.get(getContext());
mTouchSlop = configuration.getScaledTouchSlop();
mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity() / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT;
mTextSize = (int) mInputText.getTextSize();
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setTextAlign(Align.CENTER);
paint.setTextSize(mTextSize);
paint.setTypeface(mInputText.getTypeface());
ColorStateList colors = mInputText.getTextColors();
int color = colors.getColorForState(ENABLED_STATE_SET, Color.WHITE);
paint.setColor(color);
mSelectorWheelPaint = paint;
mFlingScroller = new Scroller(getContext(), null, true);
mAdjustScroller = new Scroller(getContext(), new DecelerateInterpolator(2.5f));
updateInputTextView();
}
示例14: setTextVisibility
import android.widget.TextView; //导入方法依赖的package包/类
/**
* change the visibility of text
*
* @param visibility
*/
public void setTextVisibility(boolean visibility) {
/*
1. get field in this class
private final BottomNavigationMenuView mMenuView;
2. get field in mButtons
private BottomNavigationItemView[] mButtons;
3. set text size in mButtons
private final TextView mLargeLabel
private final TextView mSmallLabel
4. change mItemHeight to only icon size in mMenuView
*/
// 1. get mMenuView
BottomNavigationMenuView mMenuView = getBottomNavigationMenuView();
// 2. get mButtons
BottomNavigationItemView[] mButtons = getBottomNavigationItemViews();
// 3. change field mShiftingMode value in mButtons
for (BottomNavigationItemView button : mButtons) {
TextView mLargeLabel = getField(button.getClass(), button, "mLargeLabel");
TextView mSmallLabel = getField(button.getClass(), button, "mSmallLabel");
if (!visibility) {
// if not record the font size, record it
if (!visibilityTextSizeRecord && !animationRecord) {
visibilityTextSizeRecord = true;
mLargeLabelSize = mLargeLabel.getTextSize();
mSmallLabelSize = mSmallLabel.getTextSize();
}
// if not visitable, set font size to 0
mLargeLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, 0);
mSmallLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, 0);
} else {
// if not record the font size, we need do nothing.
if (!visibilityTextSizeRecord)
break;
// restore it
mLargeLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, mLargeLabelSize);
mSmallLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, mSmallLabelSize);
}
}
// 4 change mItemHeight to only icon size in mMenuView
if (!visibility) {
// if not record mItemHeight
if (!visibilityHeightRecord) {
visibilityHeightRecord = true;
mItemHeight = getItemHeight();
}
// change mItemHeight to only icon size in mMenuView
// private final int mItemHeight;
// change mItemHeight
// System.out.println("mLargeLabel.getMeasuredHeight():" + getFontHeight(mSmallLabelSize));
setItemHeight(mItemHeight - getFontHeight(mSmallLabelSize));
} else {
// if not record the mItemHeight, we need do nothing.
if (!visibilityHeightRecord)
return;
// restore mItemHeight
setItemHeight(mItemHeight);
}
mMenuView.updateMenuView();
}
示例15: enableAnimation
import android.widget.TextView; //导入方法依赖的package包/类
/**
* enable or disable click item animation(text scale and icon move animation in no item shifting mode)
*
* @param enable It means the text won't scale and icon won't move when active it in no item shifting mode if false.
*/
public void enableAnimation(boolean enable) {
/*
1. get field in this class
private final BottomNavigationMenuView mMenuView;
2. get field in mButtons
private BottomNavigationItemView[] mButtons;
3. chang mShiftAmount to 0 in mButtons
private final int mShiftAmount
change mScaleUpFactor and mScaleDownFactor to 1f in mButtons
private final float mScaleUpFactor
private final float mScaleDownFactor
4. change label font size in mButtons
private final TextView mLargeLabel
private final TextView mSmallLabel
*/
// 1. get mMenuView
BottomNavigationMenuView mMenuView = getBottomNavigationMenuView();
// 2. get mButtons
BottomNavigationItemView[] mButtons = getBottomNavigationItemViews();
// 3. change field mShiftingMode value in mButtons
for (BottomNavigationItemView button : mButtons) {
TextView mLargeLabel = getField(button.getClass(), button, "mLargeLabel");
TextView mSmallLabel = getField(button.getClass(), button, "mSmallLabel");
// if disable animation, need animationRecord the source value
if (!enable) {
if (!animationRecord) {
animationRecord = true;
mShiftAmount = getField(button.getClass(), button, "mShiftAmount");
mScaleUpFactor = getField(button.getClass(), button, "mScaleUpFactor");
mScaleDownFactor = getField(button.getClass(), button, "mScaleDownFactor");
mLargeLabelSize = mLargeLabel.getTextSize();
mSmallLabelSize = mSmallLabel.getTextSize();
// System.out.println("mShiftAmount:" + mShiftAmount + " mScaleUpFactor:"
// + mScaleUpFactor + " mScaleDownFactor:" + mScaleDownFactor
// + " mLargeLabel:" + mLargeLabelSize + " mSmallLabel:" + mSmallLabelSize);
}
// disable
setField(button.getClass(), button, "mShiftAmount", 0);
setField(button.getClass(), button, "mScaleUpFactor", 1);
setField(button.getClass(), button, "mScaleDownFactor", 1);
// let the mLargeLabel font size equal to mSmallLabel
mLargeLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, mSmallLabelSize);
// debug start
// mLargeLabelSize = mLargeLabel.getTextSize();
// System.out.println("mLargeLabel:" + mLargeLabelSize);
// debug end
} else {
// haven't change the value. It means it was the first call this method. So nothing need to do.
if (!animationRecord)
return;
// enable animation
setField(button.getClass(), button, "mShiftAmount", mShiftAmount);
setField(button.getClass(), button, "mScaleUpFactor", mScaleUpFactor);
setField(button.getClass(), button, "mScaleDownFactor", mScaleDownFactor);
// restore
mLargeLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, mLargeLabelSize);
}
}
mMenuView.updateMenuView();
}