电脑
eclipse+java sdk+android sdk +ADT
1.打开Eclipse,创建一个android工程,填写项目名称为TextViewShow,勾选相应的android平台选项,填写应用名称TextViewShow,填写包名com.cn(这个随意起),填写启动的activity:ViewShow最后点击完成按钮
在向TextViewShow\res\layout\main.xml 中 添加TextView,进行属性定义,其中android:layout_width='90px' 这个很重要,这个是TextView的内容宽度,也就是说如果展示的内容长度大于90px,才能出现跑马灯的效果,否则不会出现。当然了,可以把 android:layout_width='fill_parent',那么提供的文字信息长度必须要长,大于外界的宽度;在这里,要求长度大于屏幕的宽度同时:android:ellipsize='marquee'android:marqueeRepeatLimit='marquee_forever'android:singleLine='true'其中,id的命名注意,务必是 android:id='@+id/textview' 这个形式,有个+号对于其中的android:text='@string/hello' hello的定义在res\values\strings.xml
在主体的activity ViewShow中添加主要方法,完成相应的鼠标事件注册,TextView的初始化。 TextView textview = (TextView)this.findViewById(R.id.textview); textview.setTextColor(Color.RED); //设置文本颜色 //设置字体的大小 textview.setTextSize(20); //设置文字背景textview.setBackgroundColor(Color.BLUE);/** 设置textview文字的显示 **/ String content='TextView 欢迎使用 ';textview.setText(content); 同时处理鼠标点击的事件 textview.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub TextView textviewTemp = (TextView) arg0; textviewTemp.setText('被点击了'); textviewTemp.setBackgroundColor(Color.GREEN); } });
保存代码,鼠标右键选中项目,开始运行android项目,可以看到效果