透明度--設置透明、半透明等效果


 

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

1、用android系統的透明效果:

android:background="@android:color/transparent"

例如 設置按鈕
<Button android:background="@android:color/transparent"
android:textColor="#ffffff" />

2、用ARGB來控制

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

3、設置alpha

View v = findViewById(R.id.content);//
v.getBackground().setAlpha(100);//0~255透明度值



--------------
android 窗體透明的,黑暗度等的設置技巧;;

設置透明度(這是窗體本身的透明度,非背景)
1 WindowManager.LayoutParams lp=getWindow().getAttributes();
2 lp.alpha=0.3f;
3 getWindow().setAttributes(lp);
alpha在0.0f到1.0f之間。1.0完全不透明,0.0f完全透明


設置黑暗度
1,WindowManager.LayoutParams lp=getWindow().getAttributes();
2, lp.dimAmount=0.5f;
3, getWindow().setAttributes(lp);
4, getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dimAmount在0.0f和1.0f之間,0.0f完全不暗,1.0f全暗


設置背景模糊
1,getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
2, WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
以上設置對dialog對話框同樣有效


Activity的透明、半透明效果的設置transparent
res/values/styles.xml

<resources>
<style name="Transparent">
<item name="android:windowBackground">
@color/transparent_background
</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">
@+android:style/Animation.Translucent
</item>
</style>
</resources>


res/values/color.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="transparent_background">#50000000</color>
</resources>
//注意:
//color.xml的#5000000前兩位是透明的效果參數從00--99(透明--不怎么透明),
//后6位是顏色的設置
manifest.xml


<activity
android:name=".TransparentActivity"
android:theme="@style/Transparent">
</activity>

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.Transparent);
setContentView(R.layout.transparent);
}
配置結束。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM