标签:
Drawable的设置参数为int 取值:0~255,View的设置参数为float 取值:0~1
通过Drawable对透明度的设置:
//Activity的onCreate()中,setContentView()后,添加如下代码:
int color = getResources().getColor(android.R.color.black); Drawable drawable = new ColorDrawable(color); drawable.setAlpha(150); getWindow().setBackgroundDrawable(drawable);
直接对某个View的透明度的设置:
View view = findViewById(); view.setAlpha(float);//float 取值范围0~1
对Activity也可以通过Style设置半透明:
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="Theme.Transparent" parent="android:Theme"> <item name="android:windowIsTranslucent">true</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowNoTitle">true</item> </style> </resources> //在Manifest.xml文件中的activity属性中添加 <activity android:name="....yourActivity" android:screenOrientation="portrait" android:theme="@style/Theme.Transparent" />
Android透明度的设置(transparent translucent)
标签:
原文地址:http://www.cnblogs.com/sxzheng/p/4506602.html