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

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

设置文本颜色

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

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

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

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

setBackgroundResource方法设置背景:

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 文件

<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

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

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

设置文本颜色

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

设置背景颜色

有三种方法:

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

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

setBackgroundResource方法设置背景:

以下为引用内容:
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背景颜色与背景图片设置的更多相关文章

  1. Pyqt 设置 背景颜色和背景图片、 QPalette 调色板 与QPainter 画板区别 、 不规则图片

    设置 背景颜色和背景图片 首先设置autoFillBackground属性为真然后定义一个QPalette对象设置QPalette对象的背景属性(颜色或图片)最后设置QWidget对象的Palette ...

  2. css背景颜色、背景图片,以及列表的多种样式

    背景样式 • background-color 设置元素的背景颜色.• background-image 把图像设置为背景.• background-position 设置背景图像的起始位置.• ba ...

  3. Swift自定义UINavigationController(背景颜色、背景图片、返回按钮设置、字体大小等)

    1.0  自定义UINavigationController时,背景图片.颜色等只需要设置一次,所以我们可以重写  initializa  这个方法来实现我们想要的效果 override  class ...

  4. iOS 8 设置导航栏的背景颜色和背景图片

    假设是storyboard 直接embed一个导航栏.然后在新出现的导航栏 选属性 选一下颜色就能够了 代码实现背景颜色改动:self.navigationController.navigationB ...

  5. CSS背景颜色、背景图片、平铺、定位、固定

    CSS背景颜色设置 background-color:red;如设置背景颜色为红色: 背景颜色设置支持3种写法: 颜色名 16进制 rgb CSS背景图片颜色设置 background-image:u ...

  6. Java 给 PowerPoint 文档添加背景颜色和背景图片

    在制作Powerpoint文档时,背景是非常重要的,统一的背景能让Powerpoint 演示文稿看起来更加干净美观.本文将详细讲述如何在Java应用程序中使用免费的Free Spire.Present ...

  7. 【转】Android中设置TextView的颜色setTextColor--代码中设置字体颜色

    原文网址:http://www.cnblogs.com/myphoebe/archive/2012/01/06/2314728.html android中设置TextView的颜色有方法setText ...

  8. Android TextView文字透明度和背景透明度设置

    textview1.setTextColor(Color.argb(255, 0, 255, 0)); //文字透明度 控件设为半透明: 控件名.getBackground().setAlpha(in ...

  9. Android TextView中文字通过SpannableString来设置超链接、颜色、字体等属性

    在Android中,TextView是我们最常用的用来显示文本的控件. 一般情况下,TextView中的文本都是一个样式.那么如何对于TextView中各个部分的文本来设置字体,大小,颜色,样式,以及 ...

随机推荐

  1. Java并发编程:并发容器ConcurrentHashMap

    Java并发编程:并发容器之ConcurrentHashMap(转载) 下面这部分内容转载自: http://www.haogongju.net/art/2350374 JDK5中添加了新的concu ...

  2. 简单的jQuery日期选择

    建立一个存放日期的文本框 点击文本框弹出一个选择框引用jQuery文件引用bootstrap文件 使用模态框 使用模态框的方法设置点击文本框显示模态框手动打开模态框的方法:$('id').modal( ...

  3. VMware Ubuntu安装详细过程

    参考链接: http://blog.csdn.net/u013142781/article/details/50529030

  4. jsp 常用9大内置对象

    |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ...

  5. 【转】关于Ubuntu的sources.list 的总结

    一.作用 文件/etc/apt/sources.list是一个普通可编辑的文本文件,保存了ubuntu软件更新的源服务器的地址.和sources.list功能一样的是/etc/apt/sources. ...

  6. UVA 12378 Ball Blasting Game 【Manacher回文串】

    Ball Blasting Game Morteza is playing a ball blasting game. In this game there is a chain of differe ...

  7. Linux LVM 扩展磁盘分区

    系统:centos 6.3--新建分区 fdisk -l /dev/sdc       # 查看分区 fdisk /dev/sdc          # 创建分区 :n                 ...

  8. svg转换工具

    package com.rubekid.springmvc.utils; import java.io.ByteArrayInputStream; import java.io.ByteArrayOu ...

  9. (转)SVN源码管理(上&下)

    原文地址:http://www.cnblogs.com/IPrograming/archive/2012/12/15/SVN_1.html 使用SVN进行源码管理(上) 在原来的项目中使用的源码管理工 ...

  10. [linux常用命令]查看当前文件夹或该文件夹下文件(夹)的大小

    du -sh  *(星号表示当前所有文件夹)可以查看当前目录下各个文件夹的大小,-s表示只显示当前文件夹(不加-s你可以看到所有文件夹下的子文件夹的大小,太多了),-h表示以合适的大小查看.(可以用- ...