您的位置:首页 > 移动开发 > Android开发

EditText的背景颜色的设置及android.graphics.Color的使用

2012-09-09 00:04 337 查看


1.设置EditText的背景颜色  

private test_editText=null;
test_editText=
(EditText) findViewById(R.id.EditTextInput);test_editText.setBackgroundColor(R.drawable.Black);
//设置为黑色背景

test_editText.setBackgroundColor(Color.TRANSPARENT);
//(设为透明的)
android.graphics.Color

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));

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  class