페이지

레이블이 Android-Activity인 게시물을 표시합니다. 모든 게시물 표시
레이블이 Android-Activity인 게시물을 표시합니다. 모든 게시물 표시

2011년 5월 27일 금요일

Theme.Wallpaper - 배경화면을 백그라운드로

배경화면을 백그라운드로 설정하는 예제

AndroidManifest.xml 에서 테마로 Wallpaper가 설정 되어 있다.
        <activity android:name=".app.WallpaperActivity"
                android:label="@string/activity_wallpaper"
                android:theme="@style/Theme.Wallpaper">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.SAMPLE_CODE" />
            </intent-filter>
        </activity>

Styles.xml에 Theme.Wallpaper 가 정의 되어 있으며 부모로 android:style/Theme.Wallpaper을 설정했다. -> 배경화면 설정 
    <style name="Theme.Wallpaper" parent="android:style/Theme.Wallpaper">
        <item name="android:colorForeground">#fff</item>
    </style>

WallpaperActivity Class와 매치되는 XML은 translucent_background.xml (WallpaperActivity.java)
        setContentView(R.layout.translucent_background);

Translucent Blur - Activity 반투명 테마

배경이 흐릿하게 보이는 예제.


AndroidManifest.xml 에서 테마로 Transparent가 설정 되어 있다.
        <activity android:name=".app.TranslucentBlurActivity"
                android:label="@string/activity_translucent_blur"
                android:theme="@style/Theme.Transparent">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.SAMPLE_CODE" />
            </intent-filter>
        </activity>

Styles.xml에 Theme.Transparent가 정의 되어 있으며 불투명 설정, 에니메이션 등을 설정.
     <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>

TranslucentBlurActivity Class와 매치되는 XML은 translucent_background.xml (TranslucentBlurActivity.java)
        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="fill_parent" android:layout_height="fill_parent"
    android:gravity="center_vertical|center_horizontal"
    android:text="@string/translucent_background"/>

윈도우의 설정을 불러와서 Blur(흐림효과) 설정을 해준다.
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
                WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

LayoutParams의 속성의 종류

  • FLAG_BLUR_BEHIND
  •  : 윈도우 뒤의 모든것을 흐리게 한다.
  • FLAG_DIM_BEHIND
  •  : 윈도우 뒤의 모든것을 어둡게 한다.
  • FLAG_NOT_FOCUSABLE
  •  : 윈도우 에서 키 입력 포커스를 갖지 않는다. 사용자가 키나 다른 버튼의 이벤트를 보낼수 없다. 어떤 포커스 윈도우 대신에 뒤에 남을 것이다.
  • FLAG_NOT_TOUCHABLE
  •  : 윈도우는 터치 이벤트를 절대 받을수 없다.
  • FLAG_NOT_TOUCH_MODAL
  •  : 윈도우가 포커스 될때 조차(FLAG_NOT_FOCUSABLE이 설정되지 않음) 윈도우 외부의 어떤 포인터 이벤트도 윈도우 뒤로 보내는것을 허락한다.
  • FLAG_LAYOUT_IN_SCREEN
  •  : 윈도우의 전체 화면 내에서, 경계(별명으로 상태표시줄) 주위의 장식을 무시한다.
  • FLAG_DITHER
  •  : 진동 설정
  • FLAG_KEEP_SCREEN_ON
  •  : 사용자가 윈도우 표시되는 동안, 화면을 켜고 밝게 해준다.
  • FLAG_FULLSCREEN
  •  : 모든 화면 장식(상태표시줄 등)이 창이 표시 되는 동안 숨긴다.
  • FLAG_FORCE_NOT_FULLSCREEN
  •  : FLAG_FULLSCREEN 과 화면 장식(상태표시줄 같은) 보여지는 것을 무시한다.
  • FLAG_IGNORE_CHEEK_PRESSES
  •  : 사용자의 뺨이 화면에 닫는 등의 이벤트를 감지 하지 않기 원할때 필터 설정.

Translucent - Activity 반투명 테마

Activity 가 실행될때 기존에 있던 Activity 를 반투명한 배경으로 보여준다.

        <activity android:name=".app.TranslucentActivity"
                android:label="@string/activity_translucent"
                android:theme="@style/Theme.Translucent">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.SAMPLE_CODE" />
            </intent-filter>
        </activity>

= Styles.xml
   <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>

Activity 화면 방향 설정 - setRequestedOrientation

Activity 의 화면을 동적으로 설정 할수 있습니다.

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
= 세로방향.

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
= 가로방향.


        ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED,
        ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
        ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
        ActivityInfo.SCREEN_ORIENTATION_USER,
        ActivityInfo.SCREEN_ORIENTATION_BEHIND,
        ActivityInfo.SCREEN_ORIENTATION_SENSOR,
        ActivityInfo.SCREEN_ORIENTATION_NOSENSOR,
        ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE,
        ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT,
        ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE,
        ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
        ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR,