本文整理了Java中android.widget.TextView.setSingleLine()
方法的一些代码示例,展示了TextView.setSingleLine()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextView.setSingleLine()
方法的具体详情如下:
包路径:android.widget.TextView
类名称:TextView
方法名:setSingleLine
暂无
代码示例来源:origin: stackoverflow.com
final TextView nline = new TextView(this);
nline.setSingleLine(false);
nline.setText("first line\n"+"second line\n"+"third line");
代码示例来源:origin: ZieIony/Carbon
@Override
public void setSingleLine() {
super.setSingleLine();
adjustTextSize();
}
代码示例来源:origin: BaronZ88/MinimalistWeather
/**
* 向父容器中添加TextView
*
* @param text TextView显示文字
* @param color TextView的背景颜色,如:"#FADBCC"
*/
private void addTextView(Context context, String text, int color) {
TextView textView = new TextView(context);
textView.setBackgroundColor(color);
textView.setText(text);
textView.setTextColor(textColor);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
textView.setSingleLine();
textView.setGravity(Gravity.CENTER);
textView.setLayoutParams(new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.0F));
this.addView(textView);
}
代码示例来源:origin: joyoyao/superCleanMaster
private void addTextTab(final int position, String title) {
TextView tab = new TextView(getContext());
tab.setText(title);
tab.setGravity(Gravity.CENTER);
tab.setSingleLine();
addTab(position, tab);
}
代码示例来源:origin: JohnPersano/SuperToasts
private void addTextTab(final int position, String title) {
TextView tab = new TextView(getContext());
tab.setText(title);
tab.setGravity(Gravity.CENTER);
tab.setSingleLine();
tab.setAllCaps(true);
addTab(position, tab);
}
代码示例来源:origin: H07000223/FlycoDialog_Master
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final DialogMenuItem item = mMenuItems.get(position);
LinearLayout ll_item = new LinearLayout(mContext);
ll_item.setOrientation(LinearLayout.HORIZONTAL);
ll_item.setGravity(Gravity.CENTER_VERTICAL);
ImageView iv_item = new ImageView(mContext);
iv_item.setPadding(0, 0, (int) (15 * mDisplayMetrics.density), 0);
ll_item.addView(iv_item);
TextView tv_item = new TextView(mContext);
tv_item.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
tv_item.setSingleLine(true);
tv_item.setTextColor(Color.parseColor("#303030"));
tv_item.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
ll_item.addView(tv_item);
ll_item.setPadding(item.mResId == 0 ? (int) (18 * mDisplayMetrics.density) : (int) (16 * mDisplayMetrics.density), (int) (10 * mDisplayMetrics.density), 0,
(int) (10 * mDisplayMetrics.density));
iv_item.setImageResource(item.mResId);
tv_item.setText(item.mOperName);
iv_item.setVisibility(item.mResId == 0 ? View.GONE : View.VISIBLE);
return ll_item;
}
}
代码示例来源:origin: stackoverflow.com
@Override
public View getDropDownView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = new TextView(_context);
}
TextView item = (TextView) convertView;
item.setText("asddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd");
final TextView finalItem = item;
item.post(new Runnable() {
@Override
public void run() {
finalItem.setSingleLine(false);
}
});
return item;
}
代码示例来源: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: ZieIony/Carbon
@Override
public void setSingleLine(boolean singleLine) {
super.setSingleLine(singleLine);
if (!singleLine)
super.setMaxLines(-1);
adjustTextSize();
}
代码示例来源:origin: TommyLemon/APIJSON
tvTab.setBackgroundResource(R.drawable.bg_pressed_common);
tvTab.setTextSize(18);
tvTab.setSingleLine(true);
tvTab.setText(name);
tvTab.setOnClickListener(new OnClickListener() {
代码示例来源:origin: TommyLemon/Android-ZBLibrary
tvTab.setBackgroundResource(R.drawable.to_alpha);
tvTab.setTextSize(18);
tvTab.setSingleLine(true);
tvTab.setText(name);
tvTab.setOnClickListener(new OnClickListener() {
代码示例来源:origin: sunfusheng/MarqueeView
private TextView createTextView(CharSequence text) {
TextView textView = (TextView) getChildAt((getDisplayedChild() + 1) % 3);
if (textView == null) {
textView = new TextView(getContext());
textView.setGravity(gravity);
textView.setTextColor(textColor);
textView.setTextSize(textSize);
textView.setSingleLine(singleLine);
}
textView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (onItemClickListener != null) {
onItemClickListener.onItemClick(getPosition(), (TextView) v);
}
}
});
textView.setText(text);
textView.setTag(position);
return textView;
}
代码示例来源:origin: Naoki2015/CircleDemo
mLeftLayout.setGravity(Gravity.CENTER);
mLeftText.setTextSize(DEFAULT_ACTION_TEXT_SIZE);
mLeftText.setSingleLine();
mLeftText.setGravity(Gravity.CENTER_VERTICAL);
mLeftLayout.setPadding(mOutPadding, 0, mOutPadding, 0);
mCenterText.setSingleLine();
mCenterText.setGravity(Gravity.CENTER);
mCenterText.setEllipsize(TextUtils.TruncateAt.END);
mSubTitleText.setSingleLine();
mSubTitleText.setGravity(Gravity.CENTER);
mSubTitleText.setEllipsize(TextUtils.TruncateAt.END);
代码示例来源:origin: JZ-Darkal/AndroidHttpCapture
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_loading2_dialog);
TextView mMessage = (TextView) findViewById(R.id.loading_dialog_message);
if ((mText == null) || (mText.equals(""))) {
mMessage.setVisibility(View.GONE);
} else {
mMessage.setVisibility(View.VISIBLE);
mMessage.setSingleLine(mSingleLine);
mMessage.setEllipsize(TextUtils.TruncateAt.END);
mMessage.setText(mText);
}
mProgressWheel = (ProgressWheel) findViewById(R.id.progressBar);
}
代码示例来源:origin: dongjunkun/DropDownMenu
private void addTab(@NonNull List<String> tabTexts, int i) {
final TextView tab = new TextView(getContext());
tab.setSingleLine();
tab.setEllipsize(TextUtils.TruncateAt.END);
tab.setGravity(Gravity.CENTER);
tab.setTextSize(TypedValue.COMPLEX_UNIT_PX,menuTextSize);
tab.setLayoutParams(new LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f));
tab.setTextColor(textUnselectedColor);
tab.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(menuUnselectedIcon), null);
tab.setText(tabTexts.get(i));
tab.setPadding(dpTpPx(5), dpTpPx(12), dpTpPx(5), dpTpPx(12));
//添加点击事件
tab.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
switchMenu(tab);
}
});
tabMenuView.addView(tab);
//添加分割线
if (i < tabTexts.size() - 1) {
View view = new View(getContext());
view.setLayoutParams(new LayoutParams(dpTpPx(0.5f), ViewGroup.LayoutParams.MATCH_PARENT));
view.setBackgroundColor(dividerColor);
tabMenuView.addView(view);
}
}
代码示例来源:origin: H07000223/FlycoDialog_Master
tvItem.setSingleLine(true);
tvItem.setGravity(Gravity.CENTER);
tvItem.setTextColor(mItemTextColor);
代码示例来源:origin: LitePalFramework/LitePal
@Override
public View getView(int position, View convertView, ViewGroup parent) {
List<String> dataList = getItem(position);
LinearLayout layout;
if (convertView == null) {
layout = new LinearLayout(getContext());
} else {
layout = (LinearLayout) convertView;
}
layout.removeAllViews();
int width = Utility.dp2px(getContext(), 100);
int height = Utility.dp2px(getContext(), 30);
for (String data : dataList) {
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, height);
TextView textView = new TextView(getContext());
textView.setText(data);
textView.setSingleLine(true);
textView.setEllipsize(TruncateAt.END);
textView.setGravity(Gravity.CENTER_VERTICAL);
layout.addView(textView, params);
}
return layout;
}
代码示例来源:origin: H07000223/FlycoDialog_Master
@Override
public View onCreateView() {
LinearLayout ll_container = new LinearLayout(mContext);
ll_container.setOrientation(LinearLayout.VERTICAL);
/** title */
mTvTitle = new TextView(mContext);
mTvTitle.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
mTvTitle.setSingleLine(true);
mTvTitle.setPadding(dp2px(18), dp2px(10), 0, dp2px(10));
ll_container.addView(mTvTitle);
/** listview */
mLv = new ListView(mContext);
mLv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
mLv.setCacheColorHint(Color.TRANSPARENT);
mLv.setFadingEdgeLength(0);
mLv.setVerticalScrollBarEnabled(false);
mLv.setSelector(new ColorDrawable(Color.TRANSPARENT));
ll_container.addView(mLv);
return ll_container;
}
代码示例来源:origin: lygttpod/SuperTextView
/**
* 初始化textView
*
* @param textView 对象
* @param layoutParams 对象
* @param id id
* @param textColor 颜色值
* @param textSize 字体大小
* @return 返回
*/
public TextView initText(TextView textView, LayoutParams layoutParams, int id, int textColor, int textSize) {
if (textView == null) {
textView = new TextView(mContext);
textView.setId(id);
textView.setLayoutParams(layoutParams);
textView.setTextColor(textColor);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
// textView.setGravity(Gravity.CENTER);
textView.setLines(mSetLines);
textView.setSingleLine(mSetSingleLine);
// textView.setMaxEms(mSetMaxEms);
// textView.setEllipsize(TextUtils.TruncateAt.END);
textView.setFilters(new InputFilter[]{new InputFilter.LengthFilter(mSetMaxEms) });
addView(textView);
}
return textView;
}
代码示例来源:origin: GitLqr/LQRWeChat
tvName.setTextColor(0xff000000);
tvName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
tvName.setSingleLine();
lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.CENTER_VERTICAL;
内容来源于网络,如有侵权,请联系作者删除!