Android(安卓)点击按钮,文字改变颜色
16lz
2022-01-24
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;
}
}
});
}
}
本文出自 “Android的一点一滴” 博客,请务必保留此出处http://haiyuanxi.blog.51cto.com/4230602/1010149
更多相关文章
- [置顶] Android(安卓)GridView
- Android屏蔽home键的代码,咋摁也不响应的方法
- Dalvik Optimization and Verification With dexopt
- Android(安卓)系统中 gps Location Service 的实现与架构,本文可
- 如何在android画分析图(例如 柱状图、趋势图、饼图)
- 加快Android单模块编译
- Android(安卓)Style与Theme .
- [置顶] Android(安卓)单击listview弹出popupwindow弹出框
- 加快Android单模块编译