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


textview1.setTextColor(Color.argb(255, 0, 255, 0)); //文字透明度

最关键部分,设置字体透明度 argb(Alpha, R, G, B)

  1. package net.Android.touming;  
  2.   
  3. import android.widget.TextView;  
  4. import android.os.Bundle;  
  5. import android.view.ViewGroup;  
  6. import android.app.Activity;  
  7. import android.graphics.Color;  
  8. import android.widget.LinearLayout;  
  9.   
  10. public class touming extends Activity {  
  11.   
  12.  final int WRAP_CONTENT = ViewGroup.LayoutParams.WRAP_CONTENT;  
  13.   
  14.  public void onCreate(Bundle icicle) {  
  15.   super.onCreate(icicle);  
  16.   
  17.   LinearLayout linearLayout = new LinearLayout(this);  
  18.   linearLayout.setOrientation(LinearLayout.VERTICAL);  
  19.   setContentView(linearLayout);  
  20.   
  21.   TextView textview1 = new TextView(this);  
  22.   textview1.setText("全部不透明=255");  
  23.   //textview1.setBackgroundColor(Color.argb(255, 0, 255, 0)); //背景透明度   
  24.   textview1.setTextColor(Color.argb(25502550));   //文字透明度   
  25.   linearLayout.addView(textview1, new LinearLayout.LayoutParams(WRAP_CONTENT,  
  26.     WRAP_CONTENT));  
  27.   
  28.   TextView textview2 = new TextView(this);  
  29.   textview2.setText("部分透分155");  
  30.   textview2.setBackgroundColor(Color.argb(15502550));  //背景透明度   
  31.   textview2.setTextColor(Color.argb(15502550));  //文字透明度   
  32.   linearLayout.addView(textview2, new LinearLayout.LayoutParams(WRAP_CONTENT,  
  33.     WRAP_CONTENT));  
  34.   
  35.   TextView textview3 = new TextView(this);  
  36.   textview3.setText("部分透明55");  
  37.   textview3.setBackgroundColor(Color.argb(5502550));  ///背景透明度   
  38.   textview3.setTextColor(Color.argb(5502550));  //文字透明度   
  39.   linearLayout.addView(textview3, new LinearLayout.LayoutParams(WRAP_CONTENT,  
  40.     WRAP_CONTENT));  
  41.   
  42.   TextView textview4 = new TextView(this);  
  43.   textview4.setText("全部透明0");  
  44.   //textview4.setBackgroundColor(Color.argb(0, 0, 255, 0)); //背景透明度   
  45.   textview4.setTextColor(Color.argb(002550));  //文字透明度   
  46.   linearLayout.addView(textview4, new LinearLayout.LayoutParams(WRAP_CONTENT,  
  47.     WRAP_CONTENT));  
  48.   
  49.  }  
  50.   
  51. }  

相关内容