4.TextView中有个ellipsize属性,作用是当文字过长时,该控件该如何显示,解释如下:
1.android:ellipsize=”start”—–省略号显示在开头
2.android:ellipsize=”end”——省略号显示在结尾
3.android:ellipsize=”middle”—-省略号显示在中间
4.android:ellipsize=”marquee”–以×××灯的方式显示(动画横向移动)
文字左右滚动三个属性:
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
Android中我们为了实现文本的滚动可以在ScrollView中嵌入一个TextView,其实TextView自己也可以实现多行滚动的,毕竟ScrollView必须只能有一个直接的子类布局。只要在layout中简单设置几个属性就可以轻松实现。
1.
原文地址:android string.xml前后加空格的技巧作者:forzajuve1029sf3
  这个就代表着空格
2.从xml中加载文字
getResources().getString(R.string.welcome)
3.tv.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);//下划线
tv.setText("使用代码实现下划线样式");
tv.setTextColor(Color.WHITE);
在xml文件中使用android:textStyle="bold" 可以将英文设置成粗体,但是不能将中文设置成粗体,将中文设置成粗体的方法是:
TextView tv = (TextView)findViewById(R.id.TextView01);
TextPaint tp = tv.getPaint();
tp.setFakeBoldText(true);
其他还有:
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24f);//设置成24sp
textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));//可能中文加粗无效
textView.setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC));//可能中文无效
textView.setText(Html.fromHtml("<u>"+texts+"</u>"));//下划线
textView.setTypeface(Typeface.MONOSPACE,Typeface.ITALIC);//斜体,中文有效
textView.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG );//中间加横线
textView.getPaint().setFlags(Paint. UNDERLINE_TEXT_FLAG );//底部加横线
promotionLinkText = (TextView) this .findViewById(R.id. text_promotion_link );
中间加横线
promotionLinkText .getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG );
底部加横线:
promotionLinkText .getPaint().setFlags(Paint. UNDERLINE_TEXT_FLAG );
textView1.getPaint().setAntiAlias(
true
);
// 抗锯齿
textView.getPaint().setFlags(0); // 取消设置的的划线
Android设置文字粗体的方法:
testTextView=(TextView) findViewById(R.id.testTextView);
testTextView.getPaint().setFakeBoldText(true);
英文和数字可以直接用XML去设置:
android:textStyle="bold"
转载于:https://blog.51cto.com/4789781/1225238