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

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

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

TextView.<init>介绍

暂无

代码示例

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

TextView textView = new TextView(this);
textView.setText(R.string.register);

代码示例来源: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

LayoutParams lparams = new LayoutParams(
  LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
TextView tv=new TextView(this);
tv.setLayoutParams(lparams);
tv.setText("test");
this.m_vwJokeLayout.addView(tv);

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

public class XYZ extends Activity {

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.main);

    Calendar c = Calendar.getInstance();
    System.out.println("Current time => "+c.getTime());

    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String formattedDate = df.format(c.getTime());
    // formattedDate have current date/time
    Toast.makeText(this, formattedDate, Toast.LENGTH_SHORT).show();

   // Now we display formattedDate value in TextView
    TextView txtView = new TextView(this);
    txtView.setText("Current Date and Time : "+formattedDate);
    txtView.setGravity(Gravity.CENTER);
    txtView.setTextSize(20);
    setContentView(txtView);
  }

}

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

@Override
protected void dispatchDraw(Canvas canvas) {
  super.dispatchDraw(canvas);
  final View thisView = this;
  if (thisView.isInEditMode()) {//这段代码在运行时不会执行,只会在Studio编辑预览时运行,不用在意性能问题
    int d = DensityUtil.dp2px(5);
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(0xcccccccc);
    paint.setStrokeWidth(DensityUtil.dp2px(1));
    paint.setPathEffect(new DashPathEffect(new float[]{d, d, d, d}, 1));
    canvas.drawRect(d, d, thisView.getWidth() - d, thisView.getBottom() - d, paint);
    TextView textView = new TextView(thisView.getContext());
    textView.setText(thisView.getResources().getString(R.string.srl_component_falsify, getClass().getSimpleName(), DensityUtil.px2dp(thisView.getHeight())));
    textView.setTextColor(0xcccccccc);
    textView.setGravity(Gravity.CENTER);
    //noinspection UnnecessaryLocalVariable
    View view = textView;
    view.measure(makeMeasureSpec(thisView.getWidth(), EXACTLY), makeMeasureSpec(thisView.getHeight(), EXACTLY));
    view.layout(0, 0, thisView.getWidth(), thisView.getHeight());
    view.draw(canvas);
  }
}

代码示例来源:origin: xmuSistone/AndroidPileLayout

@Override
public void addViewWhenFinishInflate() {
  textView1 = new TextView(getContext());
  textView1.setGravity(Gravity.CENTER_VERTICAL);
  textView1.setTextSize(textSize);
  textView1.setTextColor(textColor);
  LayoutParams lp1 = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
  addView(textView1, lp1);
  textView2 = new TextView(getContext());
  textView2.setGravity(Gravity.CENTER_VERTICAL);
  textView2.setTextSize(textSize);
  textView2.setTextColor(textColor);
  LayoutParams lp2 = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
  addView(textView2, lp2);
}

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

mArrowView = new ImageView(context);
mProgressView = new ImageView(context);
mTitleText = new TextView(context);
mTitleText.setTextColor(0xff666666);
mCenterLayout = new LinearLayout(context);
mCenterLayout.setGravity(Gravity.CENTER_HORIZONTAL);
mCenterLayout.setOrientation(LinearLayout.VERTICAL);

代码示例来源:origin: AppIntro/AppIntro

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.
 */
protected TextView createDefaultTabView(Context context) {
  TextView textView = new TextView(context);
  textView.setGravity(Gravity.CENTER);
  textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
  textView.setTypeface(Typeface.DEFAULT_BOLD);
  textView.setLayoutParams(new LinearLayout.LayoutParams(
      ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
  TypedValue outValue = new TypedValue();
  getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
      outValue, true);
  textView.setBackgroundResource(outValue.resourceId);
  textView.setAllCaps(true);
  int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
  textView.setPadding(padding, padding, padding, padding);
  return textView;
}

代码示例来源: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: stackoverflow.com

LinearLayout layout = findViewById(R.id.my_linear_layout);
TextView textView = new TextView(this);
layout.addView(textView);

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

/**
 * method execute order:
 * show:constrouctor---show---oncreate---onStart---onAttachToWindow
 * dismiss:dismiss---onDetachedFromWindow---onStop
 *
 * @param context
 */
public BaseAlertDialog(Context context) {
  super(context);
  widthScale(0.88f);
  mLlContainer = new LinearLayout(context);
  mLlContainer.setOrientation(LinearLayout.VERTICAL);
  /** title */
  mTvTitle = new TextView(context);
  /** content */
  mTvContent = new TextView(context);
  /**btns*/
  mLlBtns = new LinearLayout(context);
  mLlBtns.setOrientation(LinearLayout.HORIZONTAL);
  mTvBtnLeft = new TextView(context);
  mTvBtnLeft.setGravity(Gravity.CENTER);
  mTvBtnMiddle = new TextView(context);
  mTvBtnMiddle.setGravity(Gravity.CENTER);
  mTvBtnRight = new TextView(context);
  mTvBtnRight.setGravity(Gravity.CENTER);
}

代码示例来源:origin: Ramotion/expanding-collection-android

private TextView createViewForTextSwitcher(Context context) {
  TextView textView = new TextView(context);
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    textView.setTextAppearance(R.style.positionIndicatorCurrent);
  } else {
    textView.setTextAppearance(context, R.style.positionIndicatorCurrent);
  }
  textView.setLayoutParams(new TextSwitcher.LayoutParams(TextSwitcher.LayoutParams.WRAP_CONTENT, TextSwitcher.LayoutParams.WRAP_CONTENT));
  return textView;
}

代码示例来源:origin: lygttpod/SuperTextView

/**
 * 初始化textView
 *
 * @param textView     对象
 * @param layoutParams 对象
 * @return 返回
 */
public TextView getTextView(TextView textView, LinearLayout.LayoutParams layoutParams) {
  if (textView == null) {
    textView = new TextView(mContext);
    textView.setLayoutParams(layoutParams);
    textView.setVisibility(GONE);
  }
  return 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: stackoverflow.com

final int N = 10; // total number of textviews to add

final TextView[] myTextViews = new TextView[N]; // create an empty array;

for (int i = 0; i < N; i++) {
  // create a new textview
  final TextView rowTextView = new TextView(this);

  // set some properties of rowTextView or something
  rowTextView.setText("This is row #" + i);

  // add the textview to the linearlayout
  myLinearLayout.addView(rowTextView);

  // save a reference to the textview for later
  myTextViews[i] = rowTextView;
}

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

ViewGroup layout = (ViewGroup) findViewById(R.id.your_layout_id);
TextView tv = new TextView(this);
tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tv.setText("Added tv");
layout.addView(tv);

代码示例来源:origin: cSploit/android

@Override
public View getGroupView(int groupPosition, boolean isExpanded,
    View convertView, ViewGroup parent) {
  TextView row = (TextView) convertView;
  if (row == null)
    row = new TextView(mContext);
  row.setText(getGroup(groupPosition).toString());
  row.setTextSize(20);
  row.setTypeface(Typeface.DEFAULT_BOLD);
  row.setPadding(50, 0, 0, 0);
  return row;
}

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

@Override
protected void dispatchDraw(Canvas canvas) {
  super.dispatchDraw(canvas);
  final View thisView = this;
  if (thisView.isInEditMode()) {//这段代码在运行时不会执行,只会在Studio编辑预览时运行,不用在意性能问题
    int d = DensityUtil.dp2px(5);
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(0xcccccccc);
    paint.setStrokeWidth(DensityUtil.dp2px(1));
    paint.setPathEffect(new DashPathEffect(new float[]{d, d, d, d}, 1));
    canvas.drawRect(d, d, thisView.getWidth() - d, thisView.getBottom() - d, paint);
    TextView textView = new TextView(thisView.getContext());
    textView.setText(thisView.getResources().getString(R.string.srl_component_falsify, getClass().getSimpleName(), DensityUtil.px2dp(thisView.getHeight())));
    textView.setTextColor(0xcccccccc);
    textView.setGravity(Gravity.CENTER);
    //noinspection UnnecessaryLocalVariable
    View view = textView;
    view.measure(makeMeasureSpec(thisView.getWidth(), EXACTLY), makeMeasureSpec(thisView.getHeight(), EXACTLY));
    view.layout(0, 0, thisView.getWidth(), thisView.getHeight());
    view.draw(canvas);
  }
}
//</editor-fold>

代码示例来源:origin: ksoichiro/Android-ObservableScrollView

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.
 */
protected TextView createDefaultTabView(Context context) {
  TextView textView = new TextView(context);
  textView.setGravity(Gravity.CENTER);
  textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
  textView.setTypeface(Typeface.DEFAULT_BOLD);
  textView.setLayoutParams(new LinearLayout.LayoutParams(
      ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
  TypedValue outValue = new TypedValue();
  getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
      outValue, true);
  textView.setBackgroundResource(outValue.resourceId);
  textView.setAllCaps(true);
  int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
  textView.setPadding(padding, padding, padding, padding);
  return textView;
}

代码示例来源: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) {
  };
}

相关文章

TextView类方法