- 浏览: 752490 次
- 性别:
- 来自: 成都
文章分类
- 全部博客 (139)
- 玩转Android (48)
- Android创意美工 (0)
- Android杂谈 (23)
- Android实例练习 (2)
- Android ROM研究 (5)
- Android NDK开发指南 (5)
- Android NDK (0)
- Android Tips (3)
- Windows Phone 7 (5)
- iPhone (0)
- HTML5学习室 (0)
- JAVA (9)
- SSH+ibatis (8)
- PHP (0)
- IT生活 (1)
- linux (2)
- C (4)
- C++ (1)
- web 前端 (1)
- 云计算 (0)
- 设计模式 (0)
- C# (2)
- 其他 (1)
- 数据结构 (5)
- Web开发 (10)
- 数据库 (3)
- 搜索引擎 (0)
- Go语言 (0)
最新评论
-
wi100sh:
多谢分享~
玩转Android---UI篇---ImageButton(带图标的按钮) -
zhanghaichang:
好文章的。
高性能web开发技术(一) -
yingang:
引用classes.dex.dex2jar.jar 拖入 j ...
Andorid杂谈---Apk文件的反编译 -
扶摇诺:
讲解的简明易懂,多谢啦!
玩转Android---UI篇---LinearLayout(线性布局) -
a13429921973:
更为详细的图文介绍,可参考这个http://blog.csdn ...
Android ROM研究---CyanogenMod源代码下载及编译
要想设置Android的TextView控件不同的颜色有两种方式,一种是用系统内置的颜色,Android中有12种比较常见的颜色。另一种是通过配置文件colors.xml,里面设置<drawable name="name">#FFFFFF</drawable>的方式设置
下面通过一个小例子来测试下
第一种方式:在代码中设置
package org.hualang.colors; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.widget.TextView; public class ColorActivity extends Activity { /** Called when the activity is first created. */ private TextView t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); t1 = (TextView)findViewById(R.id.text01); t2 = (TextView)findViewById(R.id.text02); t3 = (TextView)findViewById(R.id.text03); t4 = (TextView)findViewById(R.id.text04); t5 = (TextView)findViewById(R.id.text05); t6 = (TextView)findViewById(R.id.text06); t7 = (TextView)findViewById(R.id.text07); t8 = (TextView)findViewById(R.id.text08); t9 = (TextView)findViewById(R.id.text09); t10 = (TextView)findViewById(R.id.text10); t11 = (TextView)findViewById(R.id.text11); t12 = (TextView)findViewById(R.id.text12); t1.setTextColor(Color.BLACK); t2.setTextColor(Color.BLUE); t3.setTextColor(Color.CYAN); t4.setTextColor(Color.DKGRAY); t5.setTextColor(Color.GRAY); t6.setTextColor(Color.GREEN); t7.setTextColor(Color.LTGRAY); t8.setTextColor(Color.MAGENTA); t9.setTextColor(Color.RED); t10.setTextColor(Color.TRANSPARENT); t11.setTextColor(Color.WHITE); t12.setTextColor(Color.YELLOW); } }
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" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="黑色" android:id="@+id/text01" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="蓝色" android:id="@+id/text02" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="蓝绿色" android:id="@+id/text03" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="深灰色" android:id="@+id/text04" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="灰色" android:id="@+id/text05" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="绿色" android:id="@+id/text06" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="浅灰色" android:id="@+id/text07" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="紫红色" android:id="@+id/text08" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="红色" android:id="@+id/text09" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="透明色" android:id="@+id/text10" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="白色" android:id="@+id/text11" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="黄色" android:id="@+id/text12" /> </LinearLayout>
运行结果如下:可以看到,第一个黑色被黑色背景覆盖了,还有就是红色后面的是透明色,是看不到的
第二种方式:在配置文件中设置好颜色,然后再代码中调用,当然还可以直接在布局文件中使用
package org.hualang.other; import android.app.Activity; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.widget.TextView; public class Other extends Activity { /** Called when the activity is first created. */ private TextView text1,text2; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); text1 = (TextView)findViewById(R.id.text1); //在代码中使用配置文件中的颜色 Resources resources = getBaseContext().getResources(); Drawable mycolor = resources.getDrawable(R.drawable.backgrounds); text1.setBackgroundDrawable(mycolor); } }
res/values/color.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <drawable name="color01">#aa00ff</drawable> <drawable name="color02">#004fa0</drawable> <drawable name="backgrounds">#00aa00</drawable> </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" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="愤怒的小鸟" android:id="@+id/text1" android:textColor="@drawable/color01" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="水果忍着" android:id="@+id/text2" android:textColor="@drawable/color02" /> </LinearLayout>
发表评论
-
Android版本自动飞行模式小蜜
2012-05-31 15:21 527可以定时切换飞行模式的一款小工具,喜欢的下! 自动飞行模式小 ... -
Android杂谈--关于解析包时错误解决方案
2012-03-21 17:17 6019最近在一个深度定制的产品上运行apk软件,由于产品所使用的系统 ... -
Android杂谈--代码混淆及proguard一些错误处理
2011-12-12 17:01 4044代码混淆说简单的其实就是为了防止别人反编译你的源代码,因为JA ... -
Android杂谈--闹钟详谈
2011-12-11 15:07 15646闹钟已经学过一段时间了,但是对它了解的不是很多,由于最近开发的 ... -
Android杂谈--闹钟详谈
2011-12-10 22:23 2闹钟已经学过一段时间了,但是对它了解的不是很多,由于最近开发的 ... -
Android内存泄露调试分享
2011-10-21 22:34 3184各位兄弟姐妹,Java开发中的内存泄露的问题经常会给 ... -
Android杂谈--开发游戏时选择游戏级别
2011-09-01 13:23 1430在开发游戏的时候,开始游戏时需要几个难度选择的选项供用户选择。 ... -
Android杂谈--Android生命周期
2011-09-01 10:48 2576引言 应用程序组件 ... -
Android杂谈--获取系统及应用程序(PackageManager)
2011-08-27 19:39 5612PackageManager是个非常好的东西,其他的详细的细节 ... -
Android杂谈---用MD5处理明文密码
2011-08-16 21:13 3166很多的网络相关的软件都需要用户名密码登录,在开发的时候像这些密 ... -
Androidz杂谈---在ContextMenu中添加/删除ListView的Item
2011-08-16 16:28 2985我们在写Android程序的时候,免不了要使用ListView ... -
Android杂谈---各种Toast
2011-07-30 21:58 1575相信各位对这个Toast已经了解的差不多了,不过我们还可以定义 ... -
Android杂谈---设置模拟器壁纸
2011-07-25 20:34 1566天天看着模拟器里面的那个图片感觉很恼火,所以干脆想将其换掉,顺 ... -
Android杂谈---TextView的跑马灯效果
2011-07-24 17:45 3369下面的是转载自农民伯伯的文章,但是有些属性还不是很清楚,所以又 ... -
Android杂谈---layout_x与layout_y的正确使用
2011-05-26 22:22 3041<?xml version="1.0" ... -
Android杂谈---分享eoeAndroid第1--16期资源
2011-05-26 22:00 2072Android杂谈---分享eoeAndroid第1--16期 ... -
Android杂谈---关于drawable文件夹的错误
2011-05-26 13:13 4972今天做一个东西的时候,用PS做了几个图片,但是更改了后缀,于是 ... -
Android杂谈---获取手机屏幕大小
2011-05-20 23:04 1600开发手机应用程序的时候,除了底层对API的掌握外,最重要的仍是 ... -
Andorid杂谈---Apk文件的反编译
2011-04-09 14:53 37711、 首先是将下载到 ... -
Android杂谈---带图片的Toast
2011-03-24 21:28 2154当需要提示的时候,我们可以用Toast来显示信息 如: T ...
相关推荐
android控件详解----TextView
TagTextView:包含标签的TextView
ExpandTextView - 展开收起功能的TextView
Android TextView-LinkBuilder Insanely easy way to create clickable links within a TextView. While creating Talon for Twitter, one of the most difficult things I encountered was creating these ...
•Android---UI篇---TextView(文本框) • •Android---UI篇---EditText(编辑框) • •Android---UI篇---DatePicker,TimePicker(日期和时间) • •Android---UI篇---ImageButton(带图标的按钮) • •Android---UI...
TextViewForFullHtml是对原生TextView解析Html格式文本的增强
android实现TextView文字部分渐变色;LinearGradientFontSpan SpannableString
android-autofittextview, 一个 TextView,它自动调整文本大小以适应它的边界 AutoFitTextView 一个 TextView,它自动调整文本大小以适应它的边界。 用法dependencies { compile 'me.grantland:autofittextview:0.2....
有两个textview,一个显示短文本,一个显示长文本,通过点击箭头,动态的显示哪个textview.
Android-html-textview.zip,显示简单HTML内容的文本视图,安卓系统是谷歌在2008年设计和制造的。操作系统主要写在爪哇,C和C 的核心组件。它是在linux内核之上构建的,具有安全性优势。
a、创建一个Android项目,然后创建一个FlowLayout继承于ViewGroup: public class FlowLayout extends ViewGroup { /** 因为只在代码中直接new,所以创建这个构造方法就可以了 */ public FlowLayout(Context ...
Android-TextView-LinkBuilder-master,创建可点击的链接,博客附件,效果请查看博客相对应项目。
代码动态改变某些textview文本颜色及其大小的方式.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
Android textview 文字中间加上图片
Android高级应用源码-跑马灯效果MarqueTextView textview 循环 跑马灯效果.zip
The library also includes a workaround to prevent TextView from crashing on specific Android versions and the possibility to load images from local drawables folder or from the Internet. This library ...
自定义View入门,博客地址: http://blog.csdn.net/jsonnan/article/details/73826185
旋转TextView文字显示方向,可参考学习一下。
EmphasisTextView - 支持部分文字高亮的 TextView