我是靠谱客的博主 俊逸刺猬,这篇文章主要介绍Android TextView背景颜色与背景图片设置,现在分享给大家,希望可以做个参考。

Android TextView 背景颜色与背景图片设置,android textview 控件,android textview 背景,

android textview 图片,android textview 颜色,android textview 组件,android textview background 。

设置文本颜色

复制代码
1
2
3
TextView textView = (TextView) findViewById(R.id.textview1); // 使用实际的颜色值设置字体颜色 textView.setTextColor(android.graphics.Color.RED);

设置背景颜色
有三种方法:

setBackgroundResource:通过颜色资源ID设置背景色。
setBackgroundColor:通过颜色值设置背景色。
setBackgroundDrawable:通过Drawable对象设置背景色。

下面分别演示如何用这3个方法来设置TextView组件的背景

setBackgroundResource方法设置背景:

复制代码
1
2
3
4
5
6
7
8
9
textView.setBackgroundResource(R.color.background); setBackgroundColor方法设置背景: textView.setBackgroundColor(android.graphics.Color.RED); setBackgroundDrawable方法设置背景: Resources resources=getBaseContext().getResources(); Drawable drawable=resources.getDrawable(R.color.background); textView.setBackgroundDrawable(drawable);

 

设置背景图片

1、将背景图片放置在 drawable-mdpi 目录下,假设图片名为 bgimg.jpg 。

2、main.xml 文件

复制代码
1
2
3
4
5
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/bgimg" />

 

 

 

 

ANDROID TEXTVIEW 背景颜色与背景图片设置
2014-06-26 16:34:51  By: dwtedx

  • dwtedx  
  • Android  
  • 0  
  • 19914  
  • 0

Android TextView 背景颜色与背景图片设置,android textview 控件,android textview 背景,

android textview 图片,android textview 颜色,android textview 组件,android textview background 。

 

设置文本颜色

 

复制代码
1
2
TextView textView =(TextView) findViewById(R.id.textview1);// 使用实际的颜色值设置字体颜色 textView.setTextColor(android.graphics.Color.RED);

设置背景颜色

有三种方法:

setBackgroundResource:通过颜色资源ID设置背景色。
setBackgroundColor:通过颜色值设置背景色。
setBackgroundDrawable:通过Drawable对象设置背景色。

 


下面分别演示如何用这3个方法来设置TextView组件的背景


setBackgroundResource方法设置背景:

 

复制代码
1
2
3
4
5
6
7
8
以下为引用内容: textView.setBackgroundResource(R.color.background); setBackgroundColor方法设置背景: textView.setBackgroundColor(android.graphics.Color.RED); setBackgroundDrawable方法设置背景:Resources resources=getBaseContext().getResources();Drawable drawable=resources.getDrawable(R.color.background); textView.setBackgroundDrawable(drawable);

设置背景图片

 


1、将背景图片放置在 drawable-mdpi 目录下,假设图片名为 bgimg.jpg 。


2、main.xml 文件

最后

以上就是俊逸刺猬最近收集整理的关于Android TextView背景颜色与背景图片设置的全部内容,更多相关Android内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(49)

评论列表共有 0 条评论

立即
投稿
返回
顶部