您的位置:首页 > 其它

设置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);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: