TextView设定背景

来源:互联网 发布:tween.js easing 编辑:程序博客网 时间:2024/05/15 00:28
动态设定方法有三种:


  • setBackgroundResource:通过颜色资源ID设置背景色。

  • setBackgroundColor:通过颜色值设置背景色。

  • setBackgroundDrawable:通过Drawable对象设置背景色。
其具体为:
Resources resources=getBaseContext().getResources(); Drawable drawable=resources.getDrawable(R.color.background); textView.setBackgroundDrawable(drawable); 

静态设定方法为:
<EditText   android:layout_width="fill_parent"   android:layout_height="wrap_content"    android:background="@drawable/bgimg"   />