package com.yanjun;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
Button button;
TextView textView;
int[] mcolors;
int colorNumber = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView = (TextView) findViewById(R.id.textView1);
button = (Button) findViewById(R.id.button1);
mcolors = new int[] { Color.BLACK, Color.BLUE, Color.CYAN,
Color.DKGRAY, Color.LTGRAY, Color.GRAY, Color.GREEN };
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if (colorNumber < mcolors.length) {
textView.setTextColor(mcolors[colorNumber]);
colorNumber++;
} else {
colorNumber = 0;
}
}
});
}
}
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
Button button;
TextView textView;
int[] mcolors;
int colorNumber = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView = (TextView) findViewById(R.id.textView1);
button = (Button) findViewById(R.id.button1);
mcolors = new int[] { Color.BLACK, Color.BLUE, Color.CYAN,
Color.DKGRAY, Color.LTGRAY, Color.GRAY, Color.GREEN };
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if (colorNumber < mcolors.length) {
textView.setTextColor(mcolors[colorNumber]);
colorNumber++;
} else {
colorNumber = 0;
}
}
});
}
}