1.设置EditText的背景颜色
2 、android.graphics.Color这个包的使用,它提供了以下12种常用颜色。
Color.BLACK
Color.BLUE
Color.CYAN
Color.DKGRAY
Color.GRAY
Color.GREEN
Color.LTGRAY
Color.MAGENTA
Color.RED
Color.TRANSPARENT
Color.WHITE
Color.YELLOW
创建了一个程序,专门为大家讲解颜色包的使用,并用TextView和linearLayout组件,把他们画到屏幕上。
package com.google.android.ColorText;
import android.widget.TextView;
import android.os.Bundle;
import android.view.ViewGroup;
import android.app.Activity;
import android.graphics.Color;
import android.widget.LinearLayout;
public class ColorText extends Activity {
final int WRAP_CONTENT = ViewGroup.LayoutParams.WRAP_CONTENT;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
setContentView(linearLayout);
TextView redTV = new TextView(this);
redTV.setText("红颜色");
redTV.setTextColor(Color.RED);
linearLayout.addView(redTV, new LinearLayout.LayoutParams(WRAP_CONTENT,
WRAP_CONTENT));
TextView greenTV = new TextView(this);
greenTV.setText("绿颜色");
greenTV.setTextColor(Color.GREEN);
linearLayout.addView(greenTV, new LinearLayout.LayoutParams(
WRAP_CONTENT, WRAP_CONTENT));
TextView blueTV = new TextView(this);
blueTV.setText("蓝颜色");
blueTV.setTextColor(Color.BLUE);
linearLayout.addView(blueTV, new LinearLayout.LayoutParams(
WRAP_CONTENT, WRAP_CONTENT));
TextView grayTV = new TextView(this);
grayTV.setText("灰颜色");
grayTV.setTextColor(Color.GRAY);
linearLayout.addView(grayTV, new LinearLayout.LayoutParams(
WRAP_CONTENT, WRAP_CONTENT));
TextView blackTV = new TextView(this);
blackTV.setText("黑颜色");
blackTV.setTextColor(Color.BLACK);
linearLayout.addView(blackTV, new LinearLayout.LayoutParams(
WRAP_CONTENT, WRAP_CONTENT));
TextView yellowTV = new TextView(this);
yellowTV.setText("黄颜色");
yellowTV.setTextColor(Color.YELLOW);
linearLayout.addView(yellowTV, new LinearLayout.LayoutParams(
WRAP_CONTENT, WRAP_CONTENT));
TextView whiteTV = new TextView(this);
whiteTV.setText("白颜色");
whiteTV.setTextColor(Color.WHITE);
linearLayout.addView(whiteTV, new LinearLayout.LayoutParams(
WRAP_CONTENT, WRAP_CONTENT));
}
}