2012년 1월 18일 수요일

Activity 에 적용한 theme 과 AlertDialog theme 을 다르게 적용하기

Activity theme 을 적용하면 해당 activity 에서 생성하는 AlertDialog 까지 theme 이 영향을 받는다.

상황)
ICS 용 앱을 개발하면서 title bar 는 GingerBread theme 를 사용하고 AlertDialog 는 ICS theme 를 따르고 싶다.

우선 안드로이드 버전별 기본 테마는 아래와 같다.
11 버전 이하의 경우 : @android:style/Theme
11 버전과 13의 경우 : @android:style/Theme.Holo
14 이상의 경우 : @android:style/Theme.DeviceDefault
인용http://starkapin.tistory.com/379

AndroidManifest.xml 파일을 열고 activity 에 11 버전의 기본 theme 를 설정한다.
<activity 
 android:name=".TestActivity" android:label="Test"
 android:theme="@android:style/Theme">
</activity>


AlertDialog.Builder 를 생성할 때 context 만 넘겨주면 activity 의 theme 를 따르게 된다.
AlertDialog.Builder builder = new AlertDialog.Builder(this);




AlertDialog.Builder 를 생성할 때 theme 값을 넣어주면 해당 theme 를 따르게 된다.
ICS 기본 테마를 따르게 했다.
AlertDialog.Builder builder = new AlertDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_DARK);





댓글 없음:

댓글 쓰기