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));
}
}
相关文章推荐
- 【android】 使用一个shape.xml文件,使用代码设置不同圆角背景颜色
- [Android_Develop]使用RGB值在代码中实时设置图片背景颜色
- color用法大全--Android布局背景颜色设置
- Android知识点记录: 使用代码设置 android 上listView的条目的点击背景颜色
- android中setBackgroundColor()中不能设置背景颜色的问题
- Android入门--android.graphics.Color 颜色设置
- android中setBackgroundColor()中不能设置背景颜色的问题
- Android 背景颜色处理[使用 Drawable.setColorFilter(),或者paint.setColorFilter()]
- Android GradientDrawable类的详解,设置activity的背景颜色渐变效果
- Flex Gumbo中如何通过contentBackgroundColor样式,设置TextInput内文本背景颜色
- Qt中设置widget背景颜色/图片的注意事项(使用样式表 setStyleSheet())
- android 各种控件颜色值的设置(使用Drawable,Color)
- Android GradientDrawable类的详解,设置activity的背景颜色渐变效果
- Android中Recyclerview使用9----Recyclerview的条目复用,出现CheckBox或者设置背景混乱问题
- android 设置html字体背景颜色
- Qt中设置widget背景颜色/图片的注意事项(使用样式表 setStyleSheet())
- Android的selector和shape基本使用和color颜色列表
- android如何设置listview点击后的item背景颜色的变换
- Android中使用Java代码动画改变背景颜色
- Android GradientDrawable类的详解,设置activity的背景颜色渐变效果