android 設置Button或者ImageButton的背景透明 半透明 透明

一:Button或者ImageButton的背景設爲透明或者半透明

半透明<Button android:background="#e0000000" ... /> 
透明<Button android:background="#00000000" ... /> android

顏色和不透明度 (alpha) 值以十六進制表示法表示。任何一種顏色的值範圍都是 0 到 255(00 到 ff)。對於 alpha,00 表示徹底透明,ff 表示徹底不透明。表達式順序是「aabbggrr」,其中「aa=alpha」(00 到 ff);「bb=blue」(00 到 ff);「gg=green」(00 到 ff);「rr=red」(00 到 ff)。例如,若是您但願對某疊加層應用不透明度爲 50% 的藍色,則應指定如下值:7fff0000 spa

二:設置背景圖片透明度(超簡單)

Java代碼 圖片

  1. View v = findViewById(R.id.content);//找到你要設透明背景的layout 的id
  2. v.getBackground().setAlpha(100);//0~255透明度值

===================================================================== get


三:設置透明效果 大概有三種


一、用android系統的透明效果

Java代碼
android:background="@android:color/transparent" 
android:background="@android:color/transparent"
例如 設置按鈕
Java代碼
<Button android:background="@android:color/transparent"   

  android:text="@+id/Button01"   

  android:id="@+id/Button01"   

  android:layout_width="wrap_content"   

  android:layout_height="wrap_content"   

  android:textColor="#ffffff" />  
< Button android:background="@android:color/transparent"
  android:text="@+id/Button01"
  android:id="@+id/Button01"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:textColor="#ffffff" />

二、用ARGB來控制

Java代碼
半透明<Button android:background="#e0000000" />  
透明<Button android:background="#00000000" /> 
半透明<Button android:background="#e0000000" />
透明<Button android:background="#00000000" />

三、設置alpha

Java代碼
View v = findViewById(R.id.content);//找到你要設透明背景的layout 的id  
v.getBackground().setAlpha(100);//透明度0~255透明度值 ,值越小越透明
相關文章
相關標籤/搜索