android 各种控件颜色值的设置(使用Drawable,Color)
来源:互联网 发布:淘宝上哪家皮草店好 编辑:程序博客网 时间:2024/05/17 06:05
android 各种控件颜色值的设置(使用Drawable,Color)
在Android中,如果需要改变控件默认的颜色,包括值的颜色,需要预先在strings.xml中设置,类似字符串,可以反复调用。Android中颜色可以使用drawable或是color来定义。
本例中strings.xml内容:
<?xml version="1.0" encoding="utf-8"?><resources> <string name="hello">Hello World, Main!</string> <string name="app_name">Color</string> <drawable name="red">#ff0000</drawable> <color name="gray">#999999</color> <color name="blue">#0000ff</color> <color name="background">#ffffff</color></resources>
上面定义了几个颜色值,下面是在布局文件中的调用,main.xml内容:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/background" ><TextView android:id="@+id/tv1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" android:textColor="@drawable/red" /><TextView android:id="@+id/tv2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" android:textColor="@color/gray" /><TextView android:id="@+id/tv3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /></LinearLayout>
在Java程序中使用:
package com.pocketdigi.color; import android.app.Activity;import android.graphics.Color;import android.os.Bundle;import android.widget.TextView; public class Main extends Activity { /** Called when the activity is first created. */TextView tv1,tv2,tv3; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tv1=(TextView)findViewById(R.id.tv1); tv2=(TextView)findViewById(R.id.tv2); tv3=(TextView)findViewById(R.id.tv3); tv3.setTextColor(Color.BLUE);//直接使用android.graphics.Color的静态变量 tv2.setTextColor(this.getResources().getColor(R.color.blue));//使用预先设置的颜色值 }}
这里以TextView为例,其他控件类似.
- android 各种控件颜色值的设置(使用Drawable,Color)
- android 各种控件颜色值的设置(使用Drawable,Color)
- android 各种控件颜色值的设置(使用Drawable,Color)
- android 各种控件颜色值的设置(使用Drawable,Color)
- android颜色color.xml设置
- Android中各种drawable的使用
- Android中各种drawable的使用
- Android中各种drawable的使用
- Android中使用颜色值作为drawable
- Android中使用颜色值作为drawable
- EditText的背景颜色的设置及android.graphics.Color的使用
- Android的各种Drawable
- Android各种Color值
- 颜色值, 设置color
- android Drawable各种类型使用
- Android入门--android.graphics.Color 颜色设置
- Android 定义 Color 和 Drawable 的方法
- Android中的“色图”(Color Drawable)资源
- MongoDB设置访问权限、设置用户
- oracle表空间
- Spring jdbc 批量更新
- camera3
- POJ 2923 Relocation (状态压缩 0-1背包)
- android 各种控件颜色值的设置(使用Drawable,Color)
- camera4
- JBOSS多实例部署出现Table already exists: JMS_MESSAGES in statement[更新]
- HDU_4317 Unfair Nim 状态压缩dp
- camera5
- 思维、找规律题目汇总
- ubuntu bluetooth 配对过程
- 2012-7-31 总结
- NAND Flash 驱动详解