Android(安卓)点击按钮,文字改变颜色
16lz
2022-01-25
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;
}
}
});
}
}
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer