Android控件之Textiew的使用
1、添加Textiew组件后修改其属性:
(1)XML文件修改:
android:textColor="#ff0000" //字体红色 android:textSize="24sp" //字体大小 android:textStyle="bold" //粗体
(2)修改java代码实现
TextView textView=(TextView)findViewById(R.id.text_view);//取得我们的TextView组件 textView.setTextColor(Color.RED);//设置成红色 textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24f);//设置成24sp textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));//加粗
2、Textiew超链接显示
(1)网站链接
xml中添加属性 android:autoLink="web" 即可,颜色自动变为蓝色
(2)电话号码链接:android:autoLink="phone"
(3)邮箱链接: android:autoLink="email"
(4)如果一个string含有多个超链接,则android:autoLink="all"。("\n"代表换行)
<string name="hello">我的博客地址是:http://flysnow.iteye.com \n我的电话是:400-34534-500\n我的email是12235@163.com</string> android:autoLink="all"
3、长文本跑马灯形式显示:
android:ellipsize="marquee" android:focusable="true" android:marqueeRepeatLimit="marquee_forever" android:focusableInTouchMode="true" android:scrollHorizontally="true" android:singleLine="true"
4、限制行数
android:maxLines="2"
和
android:singleLine="true"
5、让textview为空时,不占空间
if(dynamic.getInfo()==null){ holder.dynamic_content.setVisibility(View.GONE); }else { holder.dynamic_content.setText(dynamic.getInfo()); }
Done!