歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android TextView文字透明度和背景透明度設置

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

日期:2017/3/1 11:16:10   编辑:Linux編程

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

最關鍵部分,設置字體透明度 argb(Alpha, R, G, B)

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