Android入门--android.graphics.Color 颜色设置
来源:互联网 发布:java 微信发送消息 编辑:程序博客网 时间:2024/05/05 11:39
android.graphics.Color 包含颜色值
Color.BLACK 黑色Color.BLUE 蓝色
Color.CYAN 青绿色
Color.DKGRAY 灰黑色
Color.GRAY 灰色
Color.GREEN 绿色
Color.LTGRAY 浅灰色
Color.MAGENTA 红紫色
Color.RED 红色
Color.TRANSPARENT 透明
Color.WHITE 白色
Color.YELLOW 黄色
编程实现颜色变幻
① 新建工程
② 修改mainActivity.java 文件,添加12 个TextView 对象变量,一个LinearLayout 对象变量、一个WC
整数变量、一个LinearLayout.LayoutParams 变量。
package com.example.forwarding;import android.support.v7.app.ActionBarActivity;import android.app.AlertDialog;import android.content.DialogInterface;import android.graphics.Color;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.LinearLayout;import android.widget.TextView;public class Forwarding extends ActionBarActivity {/** 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;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);/* 实例化一个LinearLayout布局对象 */myLayout = new LinearLayout(this);/* 设置LinearLayout的布局为垂直布局 */myLayout.setOrientation(LinearLayout.VERTICAL);/* 设置LinearLayout布局背景图片 *///myLayout.setBackgroundColor(Color.BLACK);// myLayout.setBackgroundResource(R.drawable.back);/* 加载主屏布局 */setContentView(myLayout);/* 实例化一个LinearLayout布局参数,用来添加View */layoutP = new LinearLayout.LayoutParams(WC, WC);/* 构造实例化TextView对象 */constructTextView();/* 把TextView添加到LinearLayout布局中 */addTextView();/* 设置TextView文本颜色 */setTextViewColor();/* 设置TextView文本内容 */setTextViewText();}/* 设置TextView文本内容 */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("黄色");}/* 设置TextView文本颜色 */public void setTextViewColor() {black_TV.setTextColor(Color.BLACK);blue_TV.setTextColor(Color.BLUE);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);}/* 构造实例化TextView对象 */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);}/* 把TextView添加到LinearLayout布局中 */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);}}
效果如下:
0 0
- Android入门--android.graphics.Color 颜色设置
- android颜色color.xml设置
- EditText的背景颜色的设置及android.graphics.Color的使用
- android.graphics.Color
- android.graphics.Color
- android 颜色(color)
- Android 颜色Color
- Android 颜色Color
- android color.xml 颜色
- Android 颜色Color
- color用法大全--Android布局背景颜色设置
- Android Studio设置颜色拾色器工具Color Picker
- Android graphics学习笔记(1) - Color
- android color.xml 颜色大全
- android颜色配置文件color.xml
- Android 颜色Color(转)
- Android Color(颜色)解析
- Android textview设置color
- js得到url的各个部分
- Android 轻松实现仿淘宝地区选择
- Linux中文显示乱码?如何设置centos显示中文
- 用virtualBox安装centos设置网络和通信
- 如何在 Ubuntu 14.04 上通过 apt-get 安装 Apache Tomcat 7
- Android入门--android.graphics.Color 颜色设置
- Class类与JAVA反射
- 编译OpenWRT过程问题解决
- 发现和记录---js常用正则表达式语法总结:Email检查,ip地址验证,手机号码和电话号码验证
- 页面ajax交互,通过地址url先找到服务器,从数据库取值,去掉逗号,再传给页面
- linux解压多个文件
- sencha底部图标平均分配
- redis项目问题
- VectorDrawable(三)