本文整理了Java中android.widget.TextView.getTextSize()
方法的一些代码示例,展示了TextView.getTextSize()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextView.getTextSize()
方法的具体详情如下:
包路径:android.widget.TextView
类名称:TextView
方法名:getTextSize
暂无
代码示例来源:origin: stackoverflow.com
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
TextView helloWorldTextView = (TextView) rootView.findViewById(R.id.txtHelloWorld);
TextView helloWorldTextView2 = (TextView) rootView.findViewById(R.id.txtHelloWorld2);
helloWorldTextView2.setTextSize(pixelsToSp(getActivity(), helloWorldTextView.getTextSize()));
代码示例来源:origin: ankidroid/Anki-Android
private void setFont(TextView v) {
// Set the font and font size for a TextView v
float currentSize = v.getTextSize();
if (mOriginalTextSize < 0) {
mOriginalTextSize = v.getTextSize();
}
// do nothing when pref is 100% and apply scaling only once
if (mFontSizeScalePcent != 100 && Math.abs(mOriginalTextSize - currentSize) < 0.1) {
v.setTextSize(TypedValue.COMPLEX_UNIT_SP, mOriginalTextSize * (mFontSizeScalePcent / 100.0f));
}
if (mCustomTypeface != null) {
v.setTypeface(mCustomTypeface);
}
}
代码示例来源:origin: grantland/android-autofittextview
private void autofit() {
float oldTextSize = mTextView.getTextSize();
float textSize;
mIsAutofitting = true;
autofit(mTextView, mPaint, mMinTextSize, mMaxTextSize, mMaxLines, mPrecision);
mIsAutofitting = false;
textSize = mTextView.getTextSize();
if (textSize != oldTextSize) {
sendTextSizeChange(textSize, oldTextSize);
}
}
代码示例来源:origin: seven332/EhViewer
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView textView;
if (convertView == null) {
textView = (TextView) mInflater.inflate(R.layout.item_simple_list, parent, false);
} else {
textView = (TextView) convertView;
}
textView.setText(mSuggestionList.get(position).getText(textView.getTextSize()));
return textView;
}
}
代码示例来源:origin: grantland/android-autofittextview
private AutofitHelper(TextView view) {
final Context context = view.getContext();
float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
mTextView = view;
mPaint = new TextPaint();
setRawTextSize(view.getTextSize());
mMaxLines = getMaxLines(view);
mMinTextSize = scaledDensity * DEFAULT_MIN_TEXT_SIZE;
mMaxTextSize = mTextSize;
mPrecision = DEFAULT_PRECISION;
}
代码示例来源:origin: stackoverflow.com
public void correctWidth(TextView textView, int desiredWidth)
{
Paint paint = new Paint();
Rect bounds = new Rect();
paint.setTypeface(textView.getTypeface());
float textSize = textView.getTextSize();
paint.setTextSize(textSize);
String text = textView.getText().toString();
paint.getTextBounds(text, 0, text.length(), bounds);
while (bounds.width() > desiredWidth)
{
textSize--;
paint.setTextSize(textSize);
paint.getTextBounds(text, 0, text.length(), bounds);
}
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
}
代码示例来源:origin: facebook/facebook-android-sdk
Typeface typeface = textView.getTypeface();
if (typeface != null) {
textStyle.put(TEXT_SIZE, textView.getTextSize());
textStyle.put(TEXT_IS_BOLD, typeface.isBold());
textStyle.put(TEXT_IS_ITALIC, typeface.isItalic());
代码示例来源:origin: cymcsg/UltimateAndroid
private void init(Context context, AttributeSet attrs, int defStyle) {
float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
boolean sizeToFit = true;
int minTextSize = (int) scaledDensity * DEFAULT_MIN_TEXT_SIZE;
float precision = PRECISION;
if (attrs != null) {
TypedArray ta = context.obtainStyledAttributes(
attrs,
R.styleable.AutofitTextView,
defStyle,
0);
sizeToFit = ta.getBoolean(R.styleable.AutofitTextView_atv_sizeToFit, sizeToFit);
minTextSize = ta.getDimensionPixelSize(R.styleable.AutofitTextView_atv_minTextSize,
minTextSize);
precision = ta.getFloat(R.styleable.AutofitTextView_atv_precision, precision);
ta.recycle();
}
mPaint = new TextPaint();
setSizeToFit(sizeToFit);
setRawTextSize(super.getTextSize());
setRawMinTextSize(minTextSize);
setPrecision(precision);
}
代码示例来源:origin: square/assertj-android
public S hasTextSize(float size) {
isNotNull();
float actualSize = actual.getTextSize();
assertThat(actualSize) //
.overridingErrorMessage("Expected text size <%s> but was <%s>.", size, actualSize) //
.isEqualTo(size);
return myself;
}
代码示例来源:origin: stackoverflow.com
notification_text_size = text.getTextSize();
DisplayMetrics metrics = new DisplayMetrics();
WindowManager systemWM = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
代码示例来源:origin: robolectric/robolectric
@Test
public void setTextSize_shouldHandlePixels() throws Exception {
ApplicationProvider.getApplicationContext().getResources().getDisplayMetrics().density = 1.5f;
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, 10);
assertThat(textView.getTextSize()).isEqualTo(10f);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, 20);
assertThat(textView.getTextSize()).isEqualTo(20f);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void setTextSize_shouldHandleDips() throws Exception {
ApplicationProvider.getApplicationContext().getResources().getDisplayMetrics().density = 1.5f;
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
assertThat(textView.getTextSize()).isEqualTo(15f);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
assertThat(textView.getTextSize()).isEqualTo(30f);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void setTextSize_shouldHandleSp() throws Exception {
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
assertThat(textView.getTextSize()).isEqualTo(10f);
ApplicationProvider.getApplicationContext().getResources().getDisplayMetrics().scaledDensity =
1.5f;
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
assertThat(textView.getTextSize()).isEqualTo(15f);
}
代码示例来源:origin: ZieIony/Carbon
private void drawView(Canvas canvas, View v) {
int[] l = new int[2];
v.getLocationOnScreen(l);
rect.set(0, 0, v.getWidth(), v.getHeight());
rect.offset(l[0] - location[0], l[1] - location[1]);
if (drawMargins)
drawMargins(canvas, v);
if (drawPaddings)
drawPaddings(canvas, v);
if (drawBounds)
drawBounds(canvas, v);
if (drawHitRects) {
v.getHitRect(rect2);
rect2.offset(l[0] - location[0] - v.getLeft(), l[1] - location[1] - v.getTop());
if (!rect.equals(rect2)) {
paint.setColor(0x7fff0000);
canvas.drawRect(rect2, paint);
}
}
if (drawTextSizes && v instanceof TextView) {
TextView tv = (TextView) v;
paint.setTextSize(12);
float textSize = tv.getTextSize() / getResources().getDisplayMetrics().scaledDensity;
paint.setColor(Color.WHITE);
paint.setShadowLayer(2, 0, 0, 0xff000000);
canvas.drawText(textSize + "sp", rect.left, rect.top + paint.getTextSize(), paint);
}
}
代码示例来源:origin: eleme/UETool
@Override
public List<Item> getAttrs(Element element) {
List<Item> items = new ArrayList<>();
TextView textView = ((TextView) element.getView());
items.add(new TitleItem("TextView"));
items.add(new EditTextItem("Text", element, EditTextItem.Type.TYPE_TEXT, textView.getText().toString()));
items.add(new AddMinusEditItem("TextSize(sp)", element, EditTextItem.Type.TYPE_TEXT_SIZE, px2sp(textView.getTextSize())));
items.add(new EditTextItem("TextColor", element, EditTextItem.Type.TYPE_TEXT_COLOR, Util.intToHexColor(textView.getCurrentTextColor())));
List<Pair<String, Bitmap>> pairs = Util.getTextViewBitmap(textView);
for (Pair<String, Bitmap> pair : pairs) {
items.add(new BitmapItem(pair.first, pair.second));
}
items.add(new SwitchItem("IsBold", element, SwitchItem.Type.TYPE_IS_BOLD, textView.getTypeface() != null ? textView.getTypeface().isBold() : false));
return items;
}
}
代码示例来源:origin: ittianyu/BottomNavigationViewEx
mScaleDownFactor = getField(button.getClass(), button, "scaleDownFactor");
mLargeLabelSize = mLargeLabel.getTextSize();
mSmallLabelSize = mSmallLabel.getTextSize();
代码示例来源:origin: facebook/stetho
@Test
public void testSetFloat() {
mInvoker.invoke(mTextView, "setTextSize", "34");
assertEquals(34f, mTextView.getTextSize(), 0);
}
代码示例来源:origin: eleme/UETool
TextView textView = ((TextView) (item.getElement().getView()));
float textSize = Float.valueOf(s.toString());
if (textView.getTextSize() != textSize) {
textView.setTextSize(textSize);
代码示例来源:origin: naman14/Timber
songtitle.setTextSize(18 + (MusicPlayer.getTrackName().length() - 24));
Log.v("BaseNowPlayingFrag", "Title Text Size: " + songtitle.getTextSize());
代码示例来源:origin: ankidroid/Anki-Android
float size = new TextView(this).getTextSize();
mTaskHandler.setmStandardTextSize(size);
内容来源于网络,如有侵权,请联系作者删除!