Android 用户界面设计之TextView

TextView这个可以说是Android中最简单的一个控件了。该控件主要用来显示一段文字。

 

其中控件的显示设置也很简单,这里简单说一下重要的几个,控件的idlayout_weigth(宽度),layout_height(高度),text(显示文字内容)等都是比较常用和简单的设置,不在详细描述。

 

1.文字的编辑

 

设置文本的大小,颜色有两种方式:一种是通过在layout中的布局文件中设置;另一种是在Activity中的onCreate方法中进行设置。

 

xml文件设置

 

设置文字的内容为消息,大小为“20sp”(文字的单位一般采用sp),颜色是黑色,文字对其方式是居中

 

android:id="@+id/textView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="消息"

android:textSize="20sp"

android:textColor="#000000"

android:gravity="center"/>

 

Activity中的修改

 

//设置文字大小 ,大小只能传像素值

textView.setTextSize(67);

//设置颜色,三种方式。

textView.setTextColor(0xff00ff00);

textView.setTextColor(Color.BLUE);

textView.setTextColor(Color.argb(0x99,0xff,0x00,0x00));

// 通过values中的color中设置的颜色来设定。

intcolor=getResources().getColor(R.color.red);

textView.setTextColor(color);

 

 

本教程由尚硅谷教育大数据研究院出品,如需转载请注明来源。

你可能感兴趣的:(Java)