Android学习笔记之TextView
来源:互联网 发布:3g网络语音电话 编辑:程序博客网 时间:2024/05/22 08:11
两种创建方法
1. 在Activity类文件中创建
TextView tv=new TextView(this);
tv.setText(“你好”);
setContentView(tv);
2. 在layout/main.xml文件中直接创建
<TextView
android:layout_width=”fill_parent” <!-- 设置文本宽度 -->
android:layout_height=”wrap_content” <!—设置文本高度 -->
android:text=”你好”
/>
推荐使用第二种方法。在main.xml中设定文字大小
android:textSize=”20sp”
三种设置TextView文本颜色
1. 在main.xml中直接设置
android:textColor=”#00FF00”
2. 设置TextView ID:android:id=”@+id/tv”
在Activity类文件中创建:
TextView tv=(TextView)findViewById(R.id.tv);
tv.setText(Html.fromHtml(“这里是设置<font color=red>文本</font>局部颜色”));//这样设置,这段文本就相当于HTML,可以在里面写HTML标签设置样式
3. TextView tv=(TextView)findViewById(R.id.tv);
String str=” 这里是设置文本局部颜色”;
SpannableStringBuilder style=new SpannableStringBuilder(str);
Style.setSpan(new ForegroundColorSpan(Color.RED),0,3,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Style.setSpan(new ForegroundColorSpan(Color.GREEN),3,11,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(style);
设置超链接
android:autoLink=”none/web/email/phone/map/all”
跑马灯效果
android:singleLine=”true” 单行显示
android:focusable=”true”
android:ellipsize=”marquee”
android:marqueeRepeatLimit=”marquee_forever”
android:focusableInTouchMode=”true”
1. 在Activity类文件中创建
TextView tv=new TextView(this);
tv.setText(“你好”);
setContentView(tv);
2. 在layout/main.xml文件中直接创建
<TextView
android:layout_width=”fill_parent” <!-- 设置文本宽度 -->
android:layout_height=”wrap_content” <!—设置文本高度 -->
android:text=”你好”
/>
推荐使用第二种方法。在main.xml中设定文字大小
android:textSize=”20sp”
三种设置TextView文本颜色
1. 在main.xml中直接设置
android:textColor=”#00FF00”
2. 设置TextView ID:android:id=”@+id/tv”
在Activity类文件中创建:
TextView tv=(TextView)findViewById(R.id.tv);
tv.setText(Html.fromHtml(“这里是设置<font color=red>文本</font>局部颜色”));//这样设置,这段文本就相当于HTML,可以在里面写HTML标签设置样式
3. TextView tv=(TextView)findViewById(R.id.tv);
String str=” 这里是设置文本局部颜色”;
SpannableStringBuilder style=new SpannableStringBuilder(str);
Style.setSpan(new ForegroundColorSpan(Color.RED),0,3,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Style.setSpan(new ForegroundColorSpan(Color.GREEN),3,11,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(style);
设置超链接
android:autoLink=”none/web/email/phone/map/all”
跑马灯效果
android:singleLine=”true” 单行显示
android:focusable=”true”
android:ellipsize=”marquee”
android:marqueeRepeatLimit=”marquee_forever”
android:focusableInTouchMode=”true”
- Android学习笔记之TextView
- Android学习笔记之TextView
- 1.Android之TextView控件学习笔记
- Android之自定义TextView学习笔记
- android学习之TextView
- Android学习笔记02:基本视图组件之TextView
- [Android新手学习笔记11]-UI控件之TextView
- Android学习笔记-3-TextView
- Android之TextView控件学习
- Android UI学习之TextView
- Android学习路之TextView
- Android学习笔记3 - Button & TextView
- Android学习笔记10:TextView的使用
- Android学习笔记-EditText&TextView&Button&菜单栏
- Android学习笔记(17):文本框TextView类
- Android学习笔记-EditText&TextView&Button&菜单栏
- Android学习笔记·常见控件TextView
- Android学习笔记01——TextView
- PC/WM手机的IM客户端设计-----agsXMPP
- 批处理LOG_NDEBUG
- IOS开发--在navigationBar上加按钮
- [python]利用将要睡眠的时间巧妙地定时运行
- 2011-11-16开始Jbpm的开发
- Android学习笔记之TextView
- 传输线阻抗匹配:匹配电阻等于z0原因
- 使用Ajax.net 3.5 使用时出现注册扩展控件提示,解决办法
- Oracle误删表空间解决方法Error:ORA-01033
- C#无边框窗体的移动
- 仿iphone的listview下拉更新
- Android用代码完成颜色渐变处理
- Learning Deformable Models with Latent SVM
- MyEclipse连接MySQL的方法