在代码中设置TextView 的字体颜色

常用的两种方法:

1、在res文件夹下的dimens.xml 、styles.xml 或者strings.xml文件中添加<color name = "green">#00ff00</color>标签,或则在res文件夹下新建color.xml文件,在该文件中添加根标签<resource></resource>,再在根标签里添加<color>便签,然后可以在代码中通过以下方式设置:

textView.setTextColor(Context.getResources().getColor(R.color.green) );

2、textView.setTextColor(0xff00ff00);

其中:0x  表示该值是整数    ff :表示的透明度是不透明,00  表示完全透明    , 00ff00表示绿色

注意: 该种写法,参数中0x后必须是8位数,透明度(2位)+颜色值(6位)

时间: 2024-08-07 02:28:47

在代码中设置TextView 的字体颜色的相关文章

在java代码中设置TextView的字体大小,单位设为sp

要实现的效果如标题. 在dimen.xml文件中设置了<dimen name="text_size">18sp</dimen> 开始的时候,通过sizeTv.setTextSize(getResource().getDimension(R.dimen.text_size))进行设置. 此时使用as的同学会发现,as提示的getDimension返回的值即为18sp.看着挺正常的. 但是跑出来的实际效果,会比在布局文件中直接设置18sp的字体来的大!! 暂时没去弄

【转】Android中设置TextView的颜色setTextColor

原文网址:http://www.cnblogs.com/myphoebe/archive/2012/01/06/2314728.html android中设置TextView的颜色有方法setTextColor,这个方法被重载了,可以传入两种参数. public void setTextColor(int color) { mTextColor = ColorStateList.valueOf(color); updateTextColors(); } public void setTextCo

[转]Android中设置TextView的颜色setTextColor

[转自]http://txlong-onz.iteye.com/blog/1249609 Android中设置TextView的颜色setTextColor android中设置TextView的颜色有方法setTextColor,这个方法被重载了,可以传入两种参数. 1 public void setTextColor(int color) { 2 mTextColor = ColorStateList.valueOf(color); 3 updateTextColors(); 4 } 5 6

在Java代码上设置TextView字体大小

部分源码: /** * Set the default text size to a given unit and value. See {@link * TypedValue} for the possible dimension units. * * @param unit The desired dimension unit. * @param size The desired size in the given units. * * @attr ref android.R.styleab

Android中设置TextView的颜色setTextColor

tv.setTextColor(Color.parseColor("#FFFFFF")); tv.setTextColor(Color.WHITE); tv.setTextColor(Color.rgb(255, 255, 255));  //注意Color是大写C,不是color.holo_orange_dark,这样错误并没效果的 tv.setBackgroundResource(R.drawable.icon_bg_rectang_stroke); 这种方法也就是传入int co

Android代码中更改TextView颜色

项目中,需要在代码中动态更改TextView的颜色,原先使用如下: text.setTextColor(R.color.black); 为生效,查阅资料后,正确写法如下: text.setTextColor(context.getResources().getColor(R.color.black)); 或: text.setTextColor(getResources().getColorStateList(R.color.black)); Android代码中更改TextView颜色

Android设置TextView的字体

做项目的时候,需要使用到手写字体来让内容更加的美观.可是程序中默认使用的是系统的默认字体,怎么将TextView(或EditText)的字体设置成自己想要的字体呢?步骤如下: 1.下载字体文件(.ttf格式),比如Jinglei.ttf(方正静蕾的字体文件),然后将其复制到项目工程的assets/fonts目录下. 2.设置TextView的字体: 1 TextView tv = (TextView)findViewById(R.id.my_textview); 2 Typeface typef

【安卓】在java代码中设置drawableLeft时如何给定合适尺寸?

textView.setCompoundDrawables(drawable, null, null, null);时看不到图片,是因为需要手动给定drawable对应的尺寸,即用drawable.setBounds. 如果该drawable为图片,可直接drawable.setBounds(0,0,drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight());. 即直接给定图片自身尺寸,此时效果和在xml中给定一样. [安卓]在java

ASP.Net ListBox DropdownList 不同条目设置背景色和字体颜色( 转&#183; 载 )

ASP.Net ListBox DropdownList 不同条目设置背景色和字体颜色 2009-09-30  来自:真有意思 [ZU14.CN]  字体大小:[大 中 小] 摘要:在HTML展现页面上,对于html 的 select, 服务器端控件 dropdownlist, 有时需要根据不同的情况,对某些 option 项,设置不同的颜色和不同的背景色,来以示区别, 对于 HTML 控件 SELECT, 是轻而易举的,只要指定 style 即可,对于服务器端控件,因为不能直接指定style或