android.graphics.Color实践

package com.china.helloandroid;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.graphics.Color;
import android.widget.LinearLayout;

public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
private LinearLayout myLayout;
private LinearLayout.LayoutParams layoutP;
private int WC = LinearLayout.LayoutParams.WRAP_CONTENT;
private TextView black_TV, blue_TV, cyan_TV, dkgray_TV, gray_TV, green_TV, ltgray_TV,
magenta_TV, red_TV, transparent_TV, white_TV, yellow_TV;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

//实例化布局对象
myLayout = new LinearLayout(this);
//设置为垂直布局
myLayout.setOrientation(LinearLayout.VERTICAL);
//设置布局背景图片
//myLayout.setBackgroundResource(R.drawable.icon);
//加载主屏布局
setContentView(myLayout);
//实例化一个布局参数
layoutP = new LinearLayout.LayoutParams(WC, WC);
//实例化TextView对象
constructTextView();
//添加TextView对象到布局当中
addTextView();
//设置TextView颜色
setTextViewColor();
//设置TextView文字
setTextViewText();
}

public void setTextViewText(){
black_TV.setText("黑色");
blue_TV.setText("蓝色");
cyan_TV.setText("青绿色");
dkgray_TV.setText("灰黑色");
gray_TV.setText("灰色");
green_TV.setText("绿色");
ltgray_TV.setText("浅灰色");
magenta_TV.setText("红紫色");
red_TV.setText("红色");
transparent_TV.setText("透明");
white_TV.setText("白色");
yellow_TV.setText("黄色");
}

public void setTextViewColor(){
black_TV.setTextColor(Color.BLACK);
blue_TV.setTextColor(Color.BLUE);
cyan_TV.setTextColor(Color.CYAN);
dkgray_TV.setTextColor(Color.DKGRAY);
gray_TV.setTextColor(Color.GRAY);
green_TV.setTextColor(Color.GREEN);
ltgray_TV.setTextColor(Color.LTGRAY);
magenta_TV.setTextColor(Color.MAGENTA);
red_TV.setTextColor(Color.RED);
transparent_TV.setTextColor(Color.TRANSPARENT);
white_TV.setTextColor(Color.WHITE);
yellow_TV.setTextColor(Color.YELLOW);
}

public void addTextView(){
myLayout.addView(black_TV, layoutP);
myLayout.addView(blue_TV, layoutP);
myLayout.addView(cyan_TV, layoutP);
myLayout.addView(dkgray_TV, layoutP);
myLayout.addView(gray_TV, layoutP);
myLayout.addView(green_TV, layoutP);
myLayout.addView(ltgray_TV, layoutP);
myLayout.addView(magenta_TV, layoutP);
myLayout.addView(red_TV, layoutP);
myLayout.addView(transparent_TV, layoutP);
myLayout.addView(white_TV, layoutP);
myLayout.addView(yellow_TV, layoutP);
}

public void constructTextView(){
black_TV = new TextView(this);
blue_TV = new TextView(this);
cyan_TV = new TextView(this);
dkgray_TV = new TextView(this);
gray_TV = new TextView(this);
green_TV = new TextView(this);
ltgray_TV = new TextView(this);
magenta_TV = new TextView(this);
red_TV = new TextView(this);
transparent_TV = new TextView(this);
white_TV = new TextView(this);
yellow_TV = new TextView(this);
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值