android 各种控件颜色值
2013-06-15 22:05
239 查看
android 各种控件颜色值的设置(使用Drawable,Color)
作者 admin 在 9 五月 2011, 4:21 下午在Android中,如果需要改变控件默认的颜色,包括值的颜色,需要预先在strings.xml中设置,类似字符串,可以反复调用。Android中颜色可以使用drawable或是color来定义。 本例中strings.xml内容:
1 2 3 4 5 6 7 8 9 | <?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> |
1 2 3 4 5 6 7 8 910 | <?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> |
1 2 3 4 5 6 7 8 910 | 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));//使用预先设置的颜色值 } } |
相关文章推荐
- android 各种控件颜色值的设置(使用Drawable,Color)
- android 各种控件颜色值的设置(使用Drawable,Color)
- android 各种控件颜色值的设置(使用Drawable,Color)
- android 各种控件颜色值的设置(使用Drawable,Color)
- android 各种控件颜色值的设置(使用Drawable,Color)
- android 各种UI控件的特殊使用方式(不定期更新)
- android 各种常用,不易记的dialog,等控件整理
- android:布局参数,控件属性及各种xml的作用
- Canvas画各种图形及控件在屏幕中的坐标-android
- Android各种控件的事件监听 (转)
- Android之自定义各种控件
- Android 各种布局 控件内部属性大全|我是记不住了搞下来看看
- Android 视图切换库的使用SwitchLayout(可实现控件点击动画,和界面切换时的各种动画)
- android 各种常用,不易记的dialog,对话框,等控件整理
- android:布局参数,控件属性及各种xml的作用
- Android 各种控件使用方法
- 在 Android 中使用各种控件(View)
- 在 Android 中使用各种控件(View)
- android各种控件的事件监听及举例
- Android给控件添加边线的各种办法