OS/Linux

Translucent vs Translucent Blur Demo

아르비스 2010. 6. 15. 16:28

1. project 생성

2. .java
Translucent.java
package sncap.android.apis;

import sncap.android.apis.R;

import android.app.Activity;
import android.os.Bundle;

public class TranslucentDemos extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.translucent_background);
    }
}
Translucent Blur Demo.java
package sncap.android.apis;

import sncap.android.apis.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.WindowManager;

public class TransBlurDemos extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        // Have the system blur any windows behind this one.
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
                WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
       
        // See assets/res/any/layout/translucent_background.xml for this
        // view layout definition, which is being set here as
        // the content of our screen.
        setContentView(R.layout.translucent_background);
    }
}

3. xml 추가
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="fill_parent" android:layout_height="fill_parent"
    android:gravity="center_vertical|center_horizontal"
    android:text="안드로이드 Translucent Background"/>


위에 까지만 시행한 경우, background의 translucent 효과 없이 그냥 표시만 됨.

4. AndroidManifest.xml 에 추가
<Translucent>
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".TranslucentDemos"
                  android:label="@string/app_name"
                  android:theme="@style/Theme.Translucent">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
<Translucent Blur>
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".TransBlurDemos"
                  android:label="Trans Blur Demo"
                  android:theme="@style/Theme.Transparent">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
둘의 theme가 다르다
    android:theme="@style/Theme.Translucent"
     android:theme="@style/Theme.Transparent"

5. style 추가
/res/values/ 에 styles.xml 추가함
<Translucent>
    <!-- A theme that has a translucent background.  Here we explicitly specify
         that this theme is to inherit from the system's translucent theme,
         which sets up various attributes correctly. -->
    <style name="Theme.Translucent" parent="android:style/Theme.Translucent">
        <item name="android:windowBackground">@drawable/translucent_background</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:colorForeground">#fff</item>
    </style>
<Translucent Blur>
    <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="TextAppearance.Theme.PlainText" parent="android:TextAppearance.Theme">
        <item name="android:textStyle">normal</item>
    </style>

6. drawable 에서 사용하는 transparent_background 값 추가
/res/values/ 에 color.xml 추가
   <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>

    <color name="solid_red">#f00</color>
    <color name="solid_blue">#0000ff</color>
    <color name="solid_green">#f0f0</color>
    <color name="solid_yellow">#ffffff00</color>
 
위처럼 실행하면, Translucent와 Translucen blur의 차이를 볼수 있다.