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

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

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

TextView.setTextAlignment介绍

暂无

代码示例

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

// make snackbar
Snackbar mSnackbar = Snackbar.make(view, R.string.intro_snackbar, Snackbar.LENGTH_LONG);
// get snackbar view
View mView = mSnackbar.getView();
// get textview inside snackbar view
TextView mTextView = (TextView) mView.findViewById(android.support.design.R.id.snackbar_text);
// set text to center
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
  mTextView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
else
  mTextView.setGravity(Gravity.CENTER_HORIZONTAL);
// show the snackbar
mSnackbar.show();

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

private void snackBar(String toastMessage) {
  Snackbar mSnackbar = Snackbar.make(coordinatorLayout, toastMessage, Snackbar.LENGTH_LONG);
  View mView = mSnackbar.getView();
  TextView mTextView = (TextView) mView.findViewById(android.support.design.R.id.snackbar_text);
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
    mTextView.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_END);
  else
    mTextView.setGravity(Gravity.END);
  mSnackbar.show();
}

代码示例来源:origin: gearvrf/GearVRf-Demos

private void setTextViewProperties(TextView textView, Resources resources) {
  textView.setBackground(resources.getDrawable(R.drawable.rounded_corner));
  textView.setTypeface(Typeface.DEFAULT_BOLD);
  textView.setPadding(TEXT_VIEW_H_PADDING, TEXT_VIEW_V_PADDING, TEXT_VIEW_V_PADDING,
      TEXT_VIEW_V_PADDING);
  textView.setGravity(Gravity.CENTER_VERTICAL);
  textView.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START);
}

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

public static void showSnackBarError(View v, String message, Context context) {
  Snackbar snack = initSnackBar();
  ColoredSnackbar.alert(snack).show();
}

public static void showSnackBarSuccess(View v, String message, Context context) {
  Snackbar snack = initSnackBar();
  ColoredSnackbar.confirm(snack).show();
}

private initSnackBar(View v, String message, Context context){
  Snackbar snack = Snackbar.make(v, "" + message, Snackbar.LENGTH_SHORT);
  View view = snack.getView();
  TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
  tv.setTextColor(Color.WHITE);
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
    tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
  } else {
    tv.setGravity(Gravity.CENTER_HORIZONTAL);
  }
}

代码示例来源:origin: THEONE10211024/ApiDemos

public TextView getGenericView() {
  // Layout parameters for the ExpandableListView
  AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
      ViewGroup.LayoutParams.MATCH_PARENT, 64);
  TextView textView = new TextView(ExpandableList1.this);
  textView.setLayoutParams(lp);
  // Center the text vertically
  textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
  // Set the text starting position
  textView.setPaddingRelative(36, 0, 0, 0);
  // Set the text alignment
  textView.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
  return textView;
}

代码示例来源:origin: qiubiteme/android_api_demos

public TextView getGenericView() {
  // Layout parameters for the ExpandableListView
  AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
      ViewGroup.LayoutParams.MATCH_PARENT, 64);
  TextView textView = new TextView(ExpandableList1.this);
  textView.setLayoutParams(lp);
  // Center the text vertically
  textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
  // Set the text starting position
  textView.setPaddingRelative(36, 0, 0, 0);
  // Set the text alignment
  textView.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
  return textView;
}

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

private TextView addTextView(){
  TextView txtToBeAdded = new TextView(getApplicationContext());
  txtToBeAdded.setText("Tap to\nadd More");
  txtToBeAdded.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
  LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  layoutParams.setMarginStart((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics()));
  txtToBeAdded.setLayoutParams(layoutParams);
  txtToBeAdded.setClickable(true);
  txtToBeAdded.setTextColor(Color.BLACK);
  txtToBeAdded.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      selectPicture(v);
    }
  });
  return txtToBeAdded;
}

代码示例来源:origin: HuanHaiLiuXin/SnackbarUtils

/**
 * 设置TextView(@+id/snackbar_text)中文字的对齐方式 居中
 * @return
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public SnackbarUtils messageCenter(){
  if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
    if(getSnackbar()!=null){
      TextView message = (TextView) getSnackbar().getView().findViewById(R.id.snackbar_text);
      //View.setTextAlignment需要SDK>=17
      message.setTextAlignment(View.TEXT_ALIGNMENT_GRAVITY);
      message.setGravity(Gravity.CENTER);
    }
  }
  return this;
}

代码示例来源:origin: HuanHaiLiuXin/SnackbarUtils

/**
 * 设置TextView(@+id/snackbar_text)中文字的对齐方式 居右
 * @return
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public SnackbarUtils messageRight(){
  if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
    if(getSnackbar()!=null){
      TextView message = (TextView) getSnackbar().getView().findViewById(R.id.snackbar_text);
      //View.setTextAlignment需要SDK>=17
      message.setTextAlignment(View.TEXT_ALIGNMENT_GRAVITY);
      message.setGravity(Gravity.CENTER_VERTICAL|Gravity.RIGHT);
    }
  }
  return this;
}

代码示例来源:origin: HuanHaiLiuXin/SweetTips

/**
 * 设置TextView(@+id/snackbar_text)中文字的对齐方式 居中
 * @return
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public SnackbarUtils messageCenter(){
  if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
    if(getSnackbar()!=null){
      TextView message = (TextView) getSnackbar().getView().findViewById(R.id.snackbar_text);
      //View.setTextAlignment需要SDK>=17
      message.setTextAlignment(View.TEXT_ALIGNMENT_GRAVITY);
      message.setGravity(Gravity.CENTER);
    }
  }
  return this;
}

代码示例来源:origin: HuanHaiLiuXin/SweetTips

/**
 * 设置TextView(@+id/snackbar_text)中文字的对齐方式 居右
 * @return
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public SnackbarUtils messageRight(){
  if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
    if(getSnackbar()!=null){
      TextView message = (TextView) getSnackbar().getView().findViewById(R.id.snackbar_text);
      //View.setTextAlignment需要SDK>=17
      message.setTextAlignment(View.TEXT_ALIGNMENT_GRAVITY);
      message.setGravity(Gravity.CENTER_VERTICAL|Gravity.RIGHT);
    }
  }
  return this;
}

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

textViewFileName.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);

代码示例来源:origin: andresth/Kandroid

@NonNull
  @Override
  public View getView(int position, View convertView, @NonNull ViewGroup parent) {
    if (position < getCount() - (mShowAdd ? 1 : 0)) {
      convertView = mInflater.inflate(R.layout.listitem_comment, parent, false);
      convertView.setLongClickable(true);
      ((TextView) convertView.findViewById(R.id.username)).setText(Utils.fromHtml(String.format("<small>%s</small>", users == null ? mObjects.get(position).getUsername() : users.get(mObjects.get(position).getUserId()))));
      ((TextView) convertView.findViewById(R.id.date)).setText(Utils.fromHtml(String.format("<small>%tF</small>", mObjects.get(position).getDateModification())));
      ((TextView) convertView.findViewById(R.id.comment)).setText(Utils.fromHtml(mRenderer.render(mParser.parse(mObjects.get(position).getContent()))));
    } else {
      convertView = mInflater.inflate(android.R.layout.simple_list_item_1, parent, false);
      ((TextView) convertView.findViewById(android.R.id.text1)).setText(getString(R.string.taskview_fab_new_comment));
      ((TextView) convertView.findViewById(android.R.id.text1)).setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
    }
    return convertView;
  }
}

代码示例来源:origin: andresth/Kandroid

@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
  if (childPosition < getChildrenCount(groupPosition) - (mShowAdd ? 1 : 0)) {
    final KanboardTask child = (KanboardTask) getChild(groupPosition, childPosition);
    convertView = mInflater.inflate(R.layout.listitem_project_task, parent, false);
    ((TextView) convertView.findViewById(R.id.task_name)).setText(Utils.fromHtml(String.format(Locale.getDefault(), "<big><b>#%d</b></big><br />%s", child.getId(), child.getTitle())));
    if (mProject.getProjectUsers().get(child.getOwnerId()) != null)
      ((TextView) convertView.findViewById(R.id.task_owner)).setText(Utils.fromHtml(String.format(Locale.getDefault(), "<small>%s</small>", mProject.getProjectUsers().get(child.getOwnerId()))));
    else
      convertView.findViewById(R.id.task_owner).setVisibility(View.INVISIBLE);
    if (child.getCategoryId() > 0)
      ((TextView) convertView.findViewById(R.id.task_category)).setText(mProject.getCategoryHashtable().get(child.getCategoryId()).getName());
    else
      convertView.findViewById(R.id.task_category).setVisibility(View.INVISIBLE);
    if (child.getColorBackground() != null)
      convertView.findViewById(R.id.list_card).setBackgroundColor(child.getColorBackground());
  } else {
    convertView = mInflater.inflate(android.R.layout.simple_list_item_1, parent, false);
    ((TextView) convertView.findViewById(android.R.id.text1)).setText(mContext.getString(R.string.taskedit_new_task));
    ((TextView) convertView.findViewById(android.R.id.text1)).setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
  }
  return convertView;
}

代码示例来源:origin: jorgegil96/All-NBA

public void addRowToPlayersTable2(String content) {
  TableRow row = new TableRow(getActivity());
  row.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT, WRAP_CONTENT));
  int width = (int) UnitUtils.convertDpToPixel(100, getActivity());
  row.setMinimumWidth(width);
  if (content.equals("PLAYER")) {
    TextView tv = addHeaderItem(row, content);
    tv.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
    row.addView(tv);
  } else {
    TextView tv = addNormalItem(row, content);
    tv.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
    row.addView(tv);
  }
  playersTable.addView(row, new TableLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT));
}

代码示例来源:origin: geniusgithub/AndroidDialer

/**
 * Returns the text view for the contact name, creating it if necessary.
 */
public TextView getNameTextView() {
  if (mNameTextView == null) {
    mNameTextView = new TextView(getContext());
    mNameTextView.setSingleLine(true);
    mNameTextView.setEllipsize(getTextEllipsis());
    mNameTextView.setTextColor(mNameTextViewTextColor);
    mNameTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
        mNameTextViewTextSize);
    // Manually call setActivated() since this view may be added after the first
    // setActivated() call toward this whole item view.
    mNameTextView.setActivated(isActivated());
    mNameTextView.setGravity(Gravity.CENTER_VERTICAL);
    mNameTextView.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
    mNameTextView.setId(R.id.cliv_name_textview);
    if (CompatUtils.isLollipopCompatible()) {
      mNameTextView.setElegantTextHeight(false);
    }
    addView(mNameTextView);
  }
  return mNameTextView;
}

代码示例来源:origin: geniusgithub/AndroidDialer

/**
 * Returns the text view for the status, creating it if necessary.
 */
public TextView getStatusView() {
  if (mStatusView == null) {
    mStatusView = new TextView(getContext());
    mStatusView.setSingleLine(true);
    mStatusView.setEllipsize(getTextEllipsis());
    mStatusView.setTextAppearance(getContext(), android.R.style.TextAppearance_Small);
    mStatusView.setTextColor(mSecondaryTextColor);
    mStatusView.setActivated(isActivated());
    mStatusView.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
    addView(mStatusView);
  }
  return mStatusView;
}

代码示例来源:origin: geniusgithub/AndroidDialer

/**
 * Returns the text view for the search snippet, creating it if necessary.
 */
public TextView getSnippetView() {
  if (mSnippetView == null) {
    mSnippetView = new TextView(getContext());
    mSnippetView.setSingleLine(true);
    mSnippetView.setEllipsize(getTextEllipsis());
    mSnippetView.setTextAppearance(getContext(), android.R.style.TextAppearance_Small);
    mSnippetView.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
    mSnippetView.setActivated(isActivated());
    addView(mSnippetView);
  }
  return mSnippetView;
}

代码示例来源:origin: geniusgithub/AndroidDialer

/**
 * Returns the text view for the phonetic name, creating it if necessary.
 */
public TextView getPhoneticNameTextView() {
  if (mPhoneticNameTextView == null) {
    mPhoneticNameTextView = new TextView(getContext());
    mPhoneticNameTextView.setSingleLine(true);
    mPhoneticNameTextView.setEllipsize(getTextEllipsis());
    mPhoneticNameTextView.setTextAppearance(getContext(), android.R.style.TextAppearance_Small);
    mPhoneticNameTextView.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
    mPhoneticNameTextView.setTypeface(mPhoneticNameTextView.getTypeface(), Typeface.BOLD);
    mPhoneticNameTextView.setActivated(isActivated());
    mPhoneticNameTextView.setId(R.id.cliv_phoneticname_textview);
    addView(mPhoneticNameTextView);
  }
  return mPhoneticNameTextView;
}

代码示例来源:origin: geniusgithub/AndroidDialer

/**
 * Returns the text view for the data text, creating it if necessary.
 */
public TextView getDataView() {
  if (mDataView == null) {
    mDataView = new TextView(getContext());
    mDataView.setSingleLine(true);
    mDataView.setEllipsize(getTextEllipsis());
    mDataView.setTextAppearance(getContext(), R.style.TextAppearanceSmall);
    mDataView.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
    mDataView.setActivated(isActivated());
    mDataView.setId(R.id.cliv_data_view);
    if (CompatUtils.isLollipopCompatible()) {
      mDataView.setElegantTextHeight(false);
    }
    addView(mDataView);
  }
  return mDataView;
}

相关文章

TextView类方法