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

來源:互聯網
上載者:User

標籤:android   style   blog   color   os   io   

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

控制項設為半透明:

控制項名.getBackground().setAlpha(int);   int 在0-255之間

 

package net.android.alpha;import android.widget.TextView;import android.os.Bundle;import android.view.ViewGroup;import android.app.Activity;import android.graphics.Color;import android.widget.LinearLayout;public class touming extends Activity { final int WRAP_CONTENT = ViewGroup.LayoutParams.WRAP_CONTENT; public void onCreate(Bundle icicle) {  super.onCreate(icicle);  LinearLayout linearLayout = new LinearLayout(this);  linearLayout.setOrientation(LinearLayout.VERTICAL);  setContentView(linearLayout);  TextView textview1 = new TextView(this);  textview1.setText("全部不透明=255");  //textview1.setBackgroundColor(Color.argb(255, 0, 255, 0)); //背景透明度  textview1.setTextColor(Color.argb(255, 0, 255, 0));   //文字透明度  linearLayout.addView(textview1, new LinearLayout.LayoutParams(WRAP_CONTENT,    WRAP_CONTENT));  TextView textview2 = new TextView(this);  textview2.setText("部分透分155");  textview2.setBackgroundColor(Color.argb(155, 0, 255, 0));  //背景透明度  textview2.setTextColor(Color.argb(155, 0, 255, 0));  //文字透明度  linearLayout.addView(textview2, new LinearLayout.LayoutParams(WRAP_CONTENT,    WRAP_CONTENT));  TextView textview3 = new TextView(this);  textview3.setText("部分透明55");  textview3.setBackgroundColor(Color.argb(55, 0, 255, 0));  ///背景透明度  textview3.setTextColor(Color.argb(55, 0, 255, 0));  //文字透明度  linearLayout.addView(textview3, new LinearLayout.LayoutParams(WRAP_CONTENT,    WRAP_CONTENT));  TextView textview4 = new TextView(this);  textview4.setText("全部透明0");  //textview4.setBackgroundColor(Color.argb(0, 0, 255, 0)); //背景透明度  textview4.setTextColor(Color.argb(0, 0, 255, 0));  //文字透明度  linearLayout.addView(textview4, new LinearLayout.LayoutParams(WRAP_CONTENT,    WRAP_CONTENT)); }}

 

最關鍵區段,設定字型透明度 argb(Alpha, R, G, B)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.