android.widget.TextView.setTextSize()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(183)

本文整理了Java中android.widget.TextView.setTextSize()方法的一些代码示例,展示了TextView.setTextSize()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextView.setTextSize()方法的具体详情如下:
包路径:android.widget.TextView
类名称:TextView
方法名:setTextSize

TextView.setTextSize介绍

暂无

代码示例

代码示例来源:origin: scwang90/SmartRefreshLayout

protected TextView createMaskView(Context context, String text, int textSize, int gravity) {
  final TextView maskView = new TextView(context);
  maskView.setTextColor(Color.BLACK);
  maskView.setGravity(gravity | Gravity.CENTER_HORIZONTAL);
  maskView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
  maskView.setText(text);
  //noinspection UnnecessaryLocalVariable
  final View view = maskView;
  view.setBackgroundColor(Color.WHITE);
  return maskView;
}

代码示例来源:origin: stackoverflow.com

TextView txt = (TextView) findViewById(R.id.custom_fonts);  
   txt.setTextSize(30);
   Typeface font = Typeface.createFromAsset(getAssets(), "Akshar.ttf");
   Typeface font2 = Typeface.createFromAsset(getAssets(), "bangla.ttf");   
   SpannableStringBuilder SS = new SpannableStringBuilder("আমারநல்வரவு");
   SS.setSpan (new CustomTypefaceSpan("", font2), 0, 4,Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
   SS.setSpan (new CustomTypefaceSpan("", font), 4, 11,Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
   txt.setText(SS);

代码示例来源:origin: stackoverflow.com

final TextView t1=new TextView(this); 
t1.setText("Hello Android");        
  final SeekBar sk=(SeekBar) findViewById(R.id.seekBar1);     
  sk.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {       

  @Override       
  public void onStopTrackingTouch(SeekBar seekBar) {      
    // TODO Auto-generated method stub      
  }       

  @Override       
  public void onStartTrackingTouch(SeekBar seekBar) {     
    // TODO Auto-generated method stub      
  }       

  @Override       
  public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {     
    // TODO Auto-generated method stub      

    t1.setTextSize(progress);
    Toast.makeText(getApplicationContext(), String.valueOf(progress),Toast.LENGTH_LONG).show();

  }       
});

代码示例来源:origin: H07000223/FlycoTabLayout

private void updateTabStyles() {
    for (int i = 0; i < mTabCount; i++) {
      View tabView = mTabsContainer.getChildAt(i);
      tabView.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0);
      TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
      tv_tab_title.setTextColor(i == mCurrentTab ? mTextSelectColor : mTextUnselectColor);
      tv_tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextsize);
//            tv_tab_title.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0);
      if (mTextAllCaps) {
        tv_tab_title.setText(tv_tab_title.getText().toString().toUpperCase());
      }

      if (mTextBold == TEXT_BOLD_BOTH) {
        tv_tab_title.getPaint().setFakeBoldText(true);
      } else if (mTextBold == TEXT_BOLD_NONE) {
        tv_tab_title.getPaint().setFakeBoldText(false);
      }
    }
  }

代码示例来源:origin: stackoverflow.com

public static int getHeight(Context context, CharSequence text, int textSize, int deviceWidth, Typeface typeface,int padding) {
     TextView textView = new TextView(context);
     textView.setPadding(padding,0,padding,padding);
     textView.setTypeface(typeface);
     textView.setText(text, TextView.BufferType.SPANNABLE);
     textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
     int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(deviceWidth, View.MeasureSpec.AT_MOST);
     int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
     textView.measure(widthMeasureSpec, heightMeasureSpec);
     return textView.getMeasuredHeight();
   }

代码示例来源:origin: JohnPersano/SuperToasts

private void updateTabStyles() {
  for (int i = 0; i < tabCount; i++) {
    View v = tabsContainer.getChildAt(i);
    v.setBackgroundResource(tabBackgroundResId);
    if (v instanceof TextView) {
      TextView tab = (TextView) v;
      tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
      int tabTypefaceStyle = Typeface.BOLD;
      tab.setTypeface(tabTypeface, tabTypefaceStyle);
      tab.setTextColor(i == currentPosition ? tabTextColor : tabDeactivateTextColor);
    }
  }
}

代码示例来源:origin: tyzlmjj/PagerBottomTabStrip

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
  int padding = (int) TypedValue.applyDimension(
      TypedValue.COMPLEX_UNIT_DIP, 16, parent.getResources().getDisplayMetrics());
  TextView textView = new TextView(parent.getContext());
  textView.setPadding(padding, padding, padding, padding);
  textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
  return new RecyclerView.ViewHolder(textView) {
  };
}

代码示例来源:origin: hackware1993/MagicIndicator

@Override
public Object instantiateItem(ViewGroup container, int position) {
  TextView textView = new TextView(container.getContext());
  textView.setText(mDataList.get(position));
  textView.setGravity(Gravity.CENTER);
  textView.setTextColor(Color.BLACK);
  textView.setTextSize(24);
  container.addView(textView);
  return textView;
}

代码示例来源:origin: Bilibili/DanmakuFlameMaster

@Override
public void onBindViewHolder(int viewType, MyViewHolder viewHolder, BaseDanmaku danmaku, AndroidDisplayer.DisplayerConfig displayerConfig, TextPaint paint) {
  if (paint != null)
    viewHolder.mText.getPaint().set(paint);
  viewHolder.mText.setText(danmaku.text);
  viewHolder.mText.setTextColor(danmaku.textColor);
  viewHolder.mText.setTextSize(TypedValue.COMPLEX_UNIT_PX, danmaku.textSize);
  Bitmap bitmap = null;
  MyImageWare imageWare = (MyImageWare) danmaku.tag;
  if (imageWare != null) {
    bitmap = imageWare.bitmap;
    if (danmaku.text.toString().contains("textview")) {
      Log.e("DFM", "onBindViewHolder======> bitmap:" + (bitmap == null) + "  " + danmaku.tag + "url:" + imageWare.getImageUri());
    }
  }
  if (bitmap != null) {
    viewHolder.mIcon.setImageBitmap(bitmap);
    if (danmaku.text.toString().contains("textview")) {
      Log.e("DFM", "onBindViewHolder======>" + danmaku.tag + "url:" + imageWare.getImageUri());
    }
  } else {
    viewHolder.mIcon.setImageResource(R.drawable.ic_launcher);
  }
}

代码示例来源:origin: stackoverflow.com

TextView txt = (TextView) findViewById(R.id.custom_fonts);  
   txt.setTextSize(30);
   Typeface font = Typeface.createFromAsset(getAssets(), "Akshar.ttf");
   Typeface font2 = Typeface.createFromAsset(getAssets(), "bangla.ttf");   
   SpannableStringBuilder SS = new SpannableStringBuilder("আমারநல்வரவு");
   SS.setSpan (new CustomTypefaceSpan("", font2), 0, 4,Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
   SS.setSpan (new CustomTypefaceSpan("", font), 4, 11,Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
   txt.setText(SS);

代码示例来源:origin: bluejamesbond/TextJustify-Android

@Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View view = super.getView(position, convertView, parent);
    TextView textView = (TextView) view.findViewById(android.R.id.text1);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setBackgroundColor(Color.parseColor("#111111"));
    textView.setTextColor(Color.WHITE);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    return view;
  }
});

代码示例来源:origin: tyzlmjj/PagerBottomTabStrip

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
  int padding = (int) TypedValue.applyDimension(
      TypedValue.COMPLEX_UNIT_DIP, 16, parent.getResources().getDisplayMetrics());
  TextView textView = new TextView(parent.getContext());
  textView.setPadding(padding, padding, padding, padding);
  textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
  return new RecyclerView.ViewHolder(textView) {
  };
}

代码示例来源:origin: gzu-liyujiang/AndroidPicker

protected TextView createLabelView() {
  TextView labelView = new TextView(activity);
  labelView.setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
  labelView.setTextColor(labelTextColor);
  labelView.setTextSize(textSize);
  return labelView;
}

代码示例来源:origin: H07000223/FlycoTabLayout

tabView.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0);
TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
tv_tab_title.setTextColor(i == mCurrentTab ? mTextSelectColor : mTextUnselectColor);
tv_tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextsize);
  tv_tab_title.setText(tv_tab_title.getText().toString().toUpperCase());

代码示例来源:origin: stackoverflow.com

public static int getHeight(Context context, String text, int textSize, int deviceWidth) {
  TextView textView = new TextView(context);
  textView.setText(text);
  textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
  int widthMeasureSpec = MeasureSpec.makeMeasureSpec(deviceWidth, MeasureSpec.AT_MOST);
  int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
  textView.measure(widthMeasureSpec, heightMeasureSpec);
  return textView.getMeasuredHeight();
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

private void setSortNumTextSize(OriginalRankAdapter.ItemViewHolder itemViewHolder, int position) {
  if (position == 0) {
    itemViewHolder.mSortNum.setTextSize(24);
    itemViewHolder.mSortNum.setTextColor(
        getContext().getResources().getColor(R.color.colorPrimary));
  } else if (position == 1) {
    itemViewHolder.mSortNum.setTextSize(22);
    itemViewHolder.mSortNum.setTextColor(
        getContext().getResources().getColor(R.color.colorPrimary));
  } else if (position == 2) {
    itemViewHolder.mSortNum.setTextSize(18);
    itemViewHolder.mSortNum.setTextColor(
        getContext().getResources().getColor(R.color.colorPrimary));
  } else {
    itemViewHolder.mSortNum.setTextSize(16);
    itemViewHolder.mSortNum.setTextColor(
        getContext().getResources().getColor(R.color.black_alpha_30));
  }
}

代码示例来源:origin: H07000223/FlycoTabLayout

@Override
  public View getView(int position, View convertView, ViewGroup parent) {

    int padding = (int) (mDisplayMetrics.density * 10);

    TextView tv = new TextView(mContext);
    tv.setText(mItems[position]);
    tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    tv.setTextColor(Color.parseColor("#468ED0"));
    // tv.setGravity(Gravity.CENTER);
    tv.setPadding(padding, padding, padding, padding);
    AbsListView.LayoutParams lp = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT,
        AbsListView.LayoutParams.WRAP_CONTENT);
    tv.setLayoutParams(lp);
    return tv;
  }
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

private void initDialog() {
  mDialog.setCanceledOnTouchOutside(mBuilder.isTouchOutside());
  if (mBuilder.getTitleVisible()) {
    mTitle.setVisibility(View.VISIBLE);
  } else {
    mTitle.setVisibility(View.GONE);
  }
  mTitle.setText(mBuilder.getTitleText());
  mTitle.setTextColor(mBuilder.getTitleTextColor());
  mTitle.setTextSize(mBuilder.getTitleTextSize());
  mContent.setText(mBuilder.getContentText());
  mContent.setTextColor(mBuilder.getContentTextColor());
  mContent.setTextSize(mBuilder.getContentTextSize());
  mLeftBtn.setText(mBuilder.getLeftButtonText());
  mLeftBtn.setTextColor(mBuilder.getLeftButtonTextColor());
  mLeftBtn.setTextSize(mBuilder.getButtonTextSize());
  mRightBtn.setText(mBuilder.getRightButtonText());
  mRightBtn.setTextColor(mBuilder.getRightButtonTextColor());
  mRightBtn.setTextSize(mBuilder.getButtonTextSize());
  mLeftBtn.setOnClickListener(this);
  mRightBtn.setOnClickListener(this);
}

代码示例来源:origin: hidroh/materialistic

@Override
  protected void bindDropDownView(int position, View view) {
    TextView textView = (TextView) view.findViewById(android.R.id.text1);
    float textSize = AppUtils.getDimension(getContext(),
        Preferences.Theme.resolveTextSize(mEntryValues[position]),
        R.attr.contentTextSize);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    textView.setText(mEntries[position]);
  }
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

private void setSortNumTextSize(ItemViewHolder itemViewHolder, int position) {
  if (position == 0) {
    itemViewHolder.mSortNum.setTextSize(24);
    itemViewHolder.mSortNum.setTextColor(
        getContext().getResources().getColor(R.color.colorPrimary));
  } else if (position == 1) {
    itemViewHolder.mSortNum.setTextSize(22);
    itemViewHolder.mSortNum.setTextColor(
        getContext().getResources().getColor(R.color.colorPrimary));
  } else if (position == 2) {
    itemViewHolder.mSortNum.setTextSize(18);
    itemViewHolder.mSortNum.setTextColor(
        getContext().getResources().getColor(R.color.colorPrimary));
  } else {
    itemViewHolder.mSortNum.setTextSize(16);
    itemViewHolder.mSortNum.setTextColor(
        getContext().getResources().getColor(R.color.black_alpha_30));
  }
}

相关文章

TextView类方法