TextView tv01=(TextView)this.findViewById(R.id.TextView01); tv01.setText("设置文字背景色");

package com.bn.ex2h;

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.TextView;

public class Sample2_8_Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

TextView tv01=(TextView)this.findViewById(R.id.TextView01);
tv01.setText("设置文字背景色");
Resources resources=getBaseContext().getResources();
Drawable Hdrawable=resources.getDrawable(R.color.white);
tv01.setBackgroundDrawable(Hdrawable);
TextView tv02=(TextView)this.findViewById(R.id.TextView02);
tv02.setText("设置文字颜色");
tv02.setTextColor(Color.WHITE);
}
}

posted @ 2014-04-08 22:03  tfy1332  阅读(1888)  评论(0编辑  收藏  举报