2011-02-08 5 views
4

내 응용 프로그램에는 일반적인 기본 활동이 있습니다. 새 아이콘을 추가하려면이 방법으로동적으로 활동 테마 변경

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <string-array name="home_buttons_text"> 
    <item>@string/Title_1</item> 
    </string-array> 
    <array name="home_buttons_icon"> 
    <item>@drawable/google</item> 
    </array> 
    <string-array name="home_buttons_url"> 
    <item>http://www.google.com</item> 
    </string-array> 
    <array name="themes"> 
    <item>@style/my_theme</item> 
    </array> 
</resources> 

에 따라 같은 주요 활동은 난 그냥 여기에 새로운 라인을 넣어, arrays.xml에서 구성을 읽습니다.

"테마"에서는 테마의 이름이 있습니다. 이름으로 언급 된 테마를로드하고 적용하는 방법은 무엇입니까?

이 아이콘을 위해 나는

TypedArray mItemsIcons = resources.obtainTypedArray(R.array.home_buttons_icon); 
TypedArray mThemes = resources.obtainTypedArray(R.array.themes); 
. 
. 
. 
mItemsIcons.getDrawable(position); 
. 
. 
. 

을 사용했습니다하지만 테마를하는 방법에 대한 아무 생각도 없어. 테스트했습니다.

int theme = mThemes.getResourceId(position); 
setTheme(theme); 

하지만 작동하지 않습니다. 자세한 내용은 여기

체크 : http://developer.android.com/guide/topics/resources/more-resources.html#TypedArray

답변

4

당신이 setContentView(...)super.oncreate()를 호출하기 전에 setTheme(..)를 사용하고 작동해야 잘 날 정말 도움이

+0

: http://javarticles.com/2015/04/android- set-theme-dynamically.html – 8m47x