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

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

}


  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值