2012-02-10 4 views
2

테마를 변경하는 데 3 개의 버튼이 있습니다. 각 버튼을 클릭하면 내 앱 테마가 동적으로 변경되어야합니다. 프로그래밍 방식으로하는 방법.내 안드로이드 앱에 테마를 동적으로 적용하십시오.

+0

죄송하지만, 프로그래밍 스타일을 변경 [여기]를 볼 수 없습니다 http://stackoverflow.com/questions/3246447/how-to -set-the-style-attribute-programmatically-in -roid) – Dex

+1

[this] (http://www.androidengineer.com/2010/06/using-themes-in-android-applications.html)을 살펴보십시오. –

답변

0

이 부분은 link입니다.

<application android:theme="@style/CustomTheme"> 

또는 하나 명의 활동 :

<activity android:theme="@android:style/Theme.Dialog"> 
당신은 또한 응용 프로그램의 모든 활동에 스타일을 적용 할 수 있습니다

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="CodeFont" parent="@android:style/TextAppearance.Medium"> 
     <item name="android:layout_width">fill_parent</item> 
     <item name="android:layout_height">wrap_content</item> 
     <item name="android:textColor">#00FF00</item> 
     <item name="android:typeface">monospace</item> 
    </style> 
</resources> 

:하는 XML 테마 파일을 정의함으로써

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textColor="#00FF00" 
    android:typeface="monospace" 
    android:text="@string/hello" /> 

<TextView 
    style="@style/CodeFont" 
    android:text="@string/hello" /> 

+0

버튼을 클릭하면 배경색을 어떻게 바꿀 수 있습니까? – vimalatha

0

미안하지만 너는 할 수 없어. 프로그래밍 방식으로 스타일을 변경하십시오.

how to set the Style Attribute Programmatically in Android?

확실히 그러나이 원하는 동작을 달성하기위한 다른 방법이있다. 각 버튼에 대해 onclick 리스너를 설정하고 다양한 뷰 요소의 텍스트 크기, 색상, 배경 등을 프로그래밍 방식으로 변경할 수 있습니다.

0

특정 xml 파일에 대해 특정 테마를 사용할 수 있습니다. 그래픽 레이아웃의 을 사용하면 편집 설정을 사용하여 레이아웃의 테마를 변경할 수 있습니다.

다음 레이아웃으로 이동하려면 onclick 이벤트를 사용하십시오. 여기에서는 테마가 첫 번째 테마와 다를 것입니다.

2

런타임에 테마를 동적으로 설정하려면 setContentView()를 호출하기 전에 해당 활동의 onCreate() 메소드에서 setTheme()을 호출하십시오. 테마를 변경하려면 활동을 다시 시작하기 만하면됩니다.

동적으로 테마를 적용하는 방법은 다음과 같습니다. tutorial입니다.

this도 마찬가지입니다.

0

Vimalatha, 단추를 클릭 할 때 배경을 변경하려면이 코드를 단추의 onClick 기능에 추가하기 만하면됩니다.

myLinearLayout.setBackgroundColor(Color.BLUE); 

그 myLinearLayout 가정하면 당신의 LinearLayout 이름은 ...

(
관련 문제