设置TextView属性中的字体大小 颜色 背景色
2015-11-26 19:33
417 查看
首先在布局文件中
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="欢迎光临!!!"
android:textColor="#ff0000"
android:textSize="22pt" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="你想怎么样"
android:textColor="#ff0000"
android:textSize="20pt" />
</LinearLayout>
java文件中
public class MainActivity extends ActionBarActivity {
private TextView tv1;
private TextView tv2;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1 = (TextView) findViewById(R.id.textView1);
tv2 = (TextView) findViewById(R.id.textView2);
tv1.setBackgroundColor(Color.BLUE);
tv2.setBackgroundColor(Color.YELLOW);
tv1.setTextSize(20);
tv2.setTextSize(30);
tv1.setTextColor(Color.RED);
tv2.setTextColor(Color.BLACK);
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="欢迎光临!!!"
android:textColor="#ff0000"
android:textSize="22pt" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="你想怎么样"
android:textColor="#ff0000"
android:textSize="20pt" />
</LinearLayout>
java文件中
public class MainActivity extends ActionBarActivity {
private TextView tv1;
private TextView tv2;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1 = (TextView) findViewById(R.id.textView1);
tv2 = (TextView) findViewById(R.id.textView2);
tv1.setBackgroundColor(Color.BLUE);
tv2.setBackgroundColor(Color.YELLOW);
tv1.setTextSize(20);
tv2.setTextSize(30);
tv1.setTextColor(Color.RED);
tv2.setTextColor(Color.BLACK);
}
相关文章推荐
- App Nap
- hdoj Phone List 1671 (字典树记录前缀)
- 先验概率与后验概率及贝叶斯公式
- HDFS 简介
- Spark aggregator ExternalIterator 流程图
- 10个好用的在线编译/调试工具
- perf Examples
- shuoj-小6爱夜跑--Floyd记录多个最短路径
- windows下python监控系统服务
- @SuppressWarnings的使用、作用、用法
- neo4j-neoclient-example之movies 推荐
- Unity 5 全局光照GI与新的烘焙系统初探
- java实现栈结构解析
- 关于thinkphp中的验证码生成与刷新
- 第二个Sprint ------第三天
- 开发规范
- org.hibernate.PropertyValueException: not-null property references a null or transient value:
- 切换到MarkDown编辑器
- 编程思想:理解回调-CallBack
- poj 3189 Steady Cow Assignment 二分图多重匹配