1.布局文件:activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:id="@+id/myText"/>
</RelativeLayout>
2.Activity视图文件:
package com.wh.lcdtest;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;
/**
* @author wh
* @Date 2012-08-07
* @version V0.0
*/
public class MainActivity extends Activity implements OnClickListener{
TextView myTextView;
int flag;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myTextView = (TextView) findViewById(R.id.myText);
myTextView.setText("欢迎使用屏幕测试程序!!请点击屏幕开始测试!!");
myTextView.setTextColor(Color.WHITE);
myTextView.setOnClickListener(this);
flag=1;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void onClick(View view){
String mStr="LCD TEST!!";
System.out.println(mStr);
myTextView.setText("");
flag = flag%5;
switch(flag)
{
case 0:
myTextView.setBackgroundColor(Color.WHITE); break;
case 1:
myTextView.setBackgroundColor(Color.RED); break;
case 2:
myTextView.setBackgroundColor(Color.GREEN); break;
case 3:
myTextView.setBackgroundColor(Color.BLUE); break;
case 4:
myTextView.setBackgroundColor(Color.BLACK); break;
}
flag++;
}
}
3.运行效果: