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

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

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

TextView.setMaxLines介绍

暂无

代码示例

代码示例来源:origin: smuyyh/BookReader

@OnClick(R.id.tvlongIntro)
public void collapseLongIntro() {
  if (collapseLongIntro) {
    mTvlongIntro.setMaxLines(20);
    collapseLongIntro = false;
  } else {
    mTvlongIntro.setMaxLines(4);
    collapseLongIntro = true;
  }
}

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

View snackbarView = snackbar.getView();
TextView textView = (TextView) snackbarView.findViewById(android.support.design.R.id.snackbar_text);
textView.setMaxLines(5);  // show multiple line

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

final TextView descriptionText = (TextView) view.findViewById(R.id.detail_description_content);
   final TextView showAll = (TextView) view.findViewById(R.id.detail_read_all);
   showAll.setOnClickListener(new OnClickListener() {
     @Override
     public void onClick(View v) {
       showAll.setVisibility(View.INVISIBLE);
       descriptionText.setMaxLines(Integer.MAX_VALUE);
     }
   });

代码示例来源:origin: TeamNewPipe/NewPipe

private void toggleTitleAndDescription() {
  if (videoTitleToggleArrow != null) {    //it is null for tablets
    if (videoDescriptionRootLayout.getVisibility() == View.VISIBLE) {
      videoTitleTextView.setMaxLines(1);
      videoDescriptionRootLayout.setVisibility(View.GONE);
      videoTitleToggleArrow.setImageResource(R.drawable.arrow_down);
    } else {
      videoTitleTextView.setMaxLines(10);
      videoDescriptionRootLayout.setVisibility(View.VISIBLE);
      videoTitleToggleArrow.setImageResource(R.drawable.arrow_up);
    }
  }
}

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

public class LongSummaryCheckboxPreference extends CheckboxPreference
{
  public LongSummaryCheckboxPreference(Context ctx, AttributeSet attrs, int defStyle)
  {
    super(ctx, attrs, defStyle);        
  }

  public LongSummaryCheckboxPreference(Context ctx, AttributeSet attrs)
  {
    super(ctx, attrs);  
  }

  @Override
  protected void onBindView(View view)
  {       
    super.onBindView(view);

    TextView summary= (TextView)view.findViewById(android.R.id.summary);
    summary.setMaxLines(3);
  }       
}

代码示例来源:origin: facebook/facebook-android-sdk

private void initializeSocialSentenceView(Context context) {
  socialSentenceView = new TextView(context);
  socialSentenceView.setTextSize(
      TypedValue.COMPLEX_UNIT_PX,
      getResources().getDimension(R.dimen.com_facebook_likeview_text_size));
  socialSentenceView.setMaxLines(2);
  socialSentenceView.setTextColor(foregroundColor);
  socialSentenceView.setGravity(Gravity.CENTER);
  LinearLayout.LayoutParams socialSentenceViewLayout = new LinearLayout.LayoutParams(
      LayoutParams.WRAP_CONTENT,
      LayoutParams.MATCH_PARENT);
  socialSentenceView.setLayoutParams(socialSentenceViewLayout);
}

代码示例来源:origin: grantland/android-autofittextview

/**
 * {@inheritDoc}
 */
@Override
public void setMaxLines(int maxLines) {
  super.setMaxLines(maxLines);
  if (mHelper != null) {
    mHelper.setMaxLines(maxLines);
  }
}

代码示例来源:origin: k9mail/k-9

/**
 * Expand or collapse a TextView by removing or adding the 2 lines limitation
 */
private void expand(TextView v, boolean expand) {
  if (expand) {
    v.setMaxLines(Integer.MAX_VALUE);
    v.setEllipsize(null);
  } else {
    v.setMaxLines(2);
    v.setEllipsize(android.text.TextUtils.TruncateAt.END);
  }
}

代码示例来源:origin: cymcsg/UltimateAndroid

/**
 * {@inheritDoc}
 */
@Override
public void setMaxLines(int maxLines) {
  super.setMaxLines(maxLines);
  if (maxLines != mMaxLines) {
    mMaxLines = maxLines;
    refitText();
  }
}

代码示例来源:origin: Cleveroad/AdaptiveTableLayout

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
  super.onViewCreated(view, savedInstanceState);
  mSnackbar = Snackbar.make(view, R.string.changes_saved, Snackbar.LENGTH_INDEFINITE);
  TextView tv = mSnackbar.getView().findViewById(android.support.design.R.id.snackbar_text);
  tv.setMaxLines(3);
  mSnackbar.setAction("Close", new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      mSnackbar.dismiss();
    }
  });
}

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

/**
 * 设置默认lines
 *
 * @param baseTextView baseTextView
 * @param leftTopLines leftTopLines
 * @param leftLines    leftLines
 * @param bottomLines  bottomLines
 */
private void setDefaultLines(BaseTextView baseTextView, int leftTopLines, int leftLines, int bottomLines) {
  if (baseTextView != null) {
    if (leftTopLines != 0) {
      baseTextView.getTopTextView().setMaxLines(leftTopLines);
    }
    if (leftLines != 0) {
      baseTextView.getCenterTextView().setMaxLines(leftLines);
    }
    if (bottomLines != 0) {
      baseTextView.getBottomTextView().setMaxLines(bottomLines);
    }
  }
}

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

private void toggleCollapsibleContent(final VH holder, final Item item, int lineCount) {
  if (item.isContentExpanded() || lineCount <= mContentMaxLines) {
    holder.mContentTextView.setMaxLines(Integer.MAX_VALUE);
    holder.mReadMoreTextView.setVisibility(View.GONE);
    return;
  }
  holder.mContentTextView.setMaxLines(mContentMaxLines);
  holder.mReadMoreTextView.setVisibility(View.VISIBLE);
  holder.mReadMoreTextView.setText(mContext.getString(R.string.read_more, lineCount));
  holder.mReadMoreTextView.setOnClickListener(v -> {
    item.setContentExpanded(true);
    v.setVisibility(View.GONE);
    ObjectAnimator.ofInt(holder.mContentTextView, PROPERTY_MAX_LINES, lineCount)
        .setDuration((lineCount - mContentMaxLines) * DURATION_PER_LINE_MILLIS)
        .start();
  });
}

代码示例来源:origin: ZieIony/Carbon

@Override
public void setSingleLine(boolean singleLine) {
  super.setSingleLine(singleLine);
  if (!singleLine)
    super.setMaxLines(-1);
  adjustTextSize();
}

代码示例来源:origin: Naoki2015/CircleDemo

@Override
public boolean onPreDraw() {
  // 避免重复监听
  contentText.getViewTreeObserver().removeOnPreDrawListener(this);
  int linCount = contentText.getLineCount();
  if(linCount > showLines){
    if(isExpand){
      contentText.setMaxLines(Integer.MAX_VALUE);
      textPlus.setText("收起");
    }else{
      contentText.setMaxLines(showLines);
      textPlus.setText("全文");
    }
    textPlus.setVisibility(View.VISIBLE);
  }else{
    textPlus.setVisibility(View.GONE);
  }
  //Log.d("onPreDraw", "onPreDraw...");
  //Log.d("onPreDraw", linCount + "");
  return true;
}

代码示例来源:origin: Naoki2015/CircleDemo

@Override
  public void onClick(View view) {
    String textStr = textPlus.getText().toString().trim();
    if("全文".equals(textStr)){
      contentText.setMaxLines(Integer.MAX_VALUE);
      textPlus.setText("收起");
      setExpand(true);
    }else{
      contentText.setMaxLines(showLines);
      textPlus.setText("全文");
      setExpand(false);
    }
    //通知外部状态已变更
    if(expandStatusListener != null){
      expandStatusListener.statusChange(isExpand());
    }
  }
});

代码示例来源:origin: ZieIony/Carbon

@Override
public void setMaxLines(int maxLines) {
  super.setMaxLines(maxLines);
  fixSpannableEllipsis();
  this.maxLines = maxLines;
  adjustTextSize();
}

代码示例来源:origin: android-hacker/VirtualXposed

private void fixTextView(ViewGroup viewGroup) {
  int count = viewGroup.getChildCount();
  for (int i = 0; i < count; i++) {
    View v = viewGroup.getChildAt(i);
    if (v instanceof TextView) {
      TextView tv = (TextView) v;
      if (isSingleLine(tv)) {
        tv.setSingleLine(false);
        tv.setMaxLines(1);
      }
    } else if (v instanceof ViewGroup) {
      fixTextView((ViewGroup) v);
    }
  }
}

代码示例来源:origin: TeamNewPipe/NewPipe

@Override
public void showLoading() {
  super.showLoading();
  animateView(contentRootLayoutHiding, false, 200);
  animateView(spinnerToolbar, false, 200);
  animateView(thumbnailPlayButton, false, 50);
  animateView(detailDurationView, false, 100);
  videoTitleTextView.setText(name != null ? name : "");
  videoTitleTextView.setMaxLines(1);
  animateView(videoTitleTextView, true, 0);
  videoDescriptionRootLayout.setVisibility(View.GONE);
  if (videoTitleToggleArrow != null) {    //phone
    videoTitleToggleArrow.setImageResource(R.drawable.arrow_down);
    videoTitleToggleArrow.setVisibility(View.GONE);
  } else {    //tablet
    final View related = (View) relatedStreamRootLayout.getParent();
    //don`t need to hide it if related streams are disabled
    if (related.getVisibility() == View.VISIBLE) {
      related.setVisibility(View.INVISIBLE);
    }
  }
  videoTitleRoot.setClickable(false);
  imageLoader.cancelDisplayTask(thumbnailImageView);
  imageLoader.cancelDisplayTask(uploaderThumb);
  thumbnailImageView.setImageBitmap(null);
  uploaderThumb.setImageBitmap(null);
}

代码示例来源:origin: Naoki2015/CircleDemo

private void initView() {
  setOrientation(LinearLayout.VERTICAL);
  LayoutInflater.from(getContext()).inflate(R.layout.layout_magic_text, this);
  contentText = (TextView) findViewById(R.id.contentText);
  if(showLines > 0){
    contentText.setMaxLines(showLines);
  }
  textPlus = (TextView) findViewById(R.id.textPlus);
  textPlus.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
      String textStr = textPlus.getText().toString().trim();
      if("全文".equals(textStr)){
        contentText.setMaxLines(Integer.MAX_VALUE);
        textPlus.setText("收起");
        setExpand(true);
      }else{
        contentText.setMaxLines(showLines);
        textPlus.setText("全文");
        setExpand(false);
      }
      //通知外部状态已变更
      if(expandStatusListener != null){
        expandStatusListener.statusChange(isExpand());
      }
    }
  });
}

代码示例来源:origin: ankidroid/Anki-Android

public static Snackbar showSnackbar(Activity activity, String mainText, int length,
              int actionTextResource, View.OnClickListener listener, View root,
              Snackbar.Callback callback) {
  if (root == null) {
    root = activity.findViewById(android.R.id.content);
    if (root == null) {
      Timber.e("Could not show Snackbar due to null View");
      return null;
    }
  }
  Snackbar sb = Snackbar.make(root, mainText, length);
  if (listener != null) {
    sb.setAction(actionTextResource, listener);
  }
  if (callback != null) {
    sb.addCallback(callback);
  }
  // Make the text white to avoid interference from our theme colors.
  View view = sb.getView();
  TextView tv = view.findViewById(com.google.android.material.R.id.snackbar_text);
  TextView action = view.findViewById(com.google.android.material.R.id.snackbar_action);
  if (tv != null && action != null) {
    tv.setTextColor(Color.WHITE);
    action.setTextColor(ContextCompat.getColor(activity, R.color.material_light_blue_500));
    tv.setMaxLines(2);  // prevent tablets from truncating to 1 line
  }
  sb.show();
  return sb;
}

相关文章

TextView类方法