TranslucentBlur

来源:互联网 发布:淘宝哪有一元抢购 编辑:程序博客网 时间:2024/05/22 15:00

 

public class A extends Activity {

 

    @Override

    protected void onCreate(Bundle icicle) {

 

        super.onCreate(icicle);

 

 

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,

                WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

//使用android:theme="@style/Theme.Wallpaper"时,注意将上面一段代码注释掉!

 

 

        setContentView(R.layout.translucent_background);

    }

}

translucent_background.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/text"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:gravity="center_vertical|center_horizontal"
    android:text="@string/translucent_background"/>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.ac"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name"
 android:theme="@style/Theme.Transparent"
>
  <!--  android:theme="@style/Theme.Wallpaper" -->
        <activity android:name=".MainA"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
      
       
    </application>
    <uses-sdk android:minSdkVersion="8" />
</manifest>
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme" parent="android:Theme">
    </style>
  <style name="Theme.Transparent">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item>
        <item name="android:windowBackground">@drawable/transparent_background</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:colorForeground">#fff</item>
    </style>
    <style name="Theme.Wallpaper" parent="android:style/Theme.Wallpaper">
        <item name="android:colorForeground">#fff</item>
    </style>
</resources>
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <drawable name="red">#7f00</drawable>
    <drawable name="blue">#770000ff</drawable>
    <drawable name="green">#7700ff00</drawable>
<drawable name="yellow">#77ffff00</drawable>
<drawable name="screen_background_black">#ff000000</drawable>
    <drawable name="translucent_background">#e0000000</drawable>
    <drawable name="transparent_background">#00000000</drawable>
</resources>
意外的效果!