Android——透明度设置

来源:互联网 发布:人和卫星直播软件 编辑:程序博客网 时间:2024/06/03 10:51

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设置

<?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" />


0 0
原创粉丝点击