2014-01-20 2 views
0

테마 클래스가 "Util"이고 3 가지 버튼이있어 내 활동에서 테마를 변경할 수 있습니다. 나는 모든 텍스트 뷰 테마와 잘 작동을 테마로, 글고는 텍스트 뷰도 작동하지 않는버튼으로 변경 나를 만든 어떤 작동하지를 적용하면. 내가 발견 한 사실은 TextView와 같이 텍스트 색상 필드가 비어 있어야한다는 것입니다. Button을 TextView로 변경했습니다. 그러나 이러한 버튼 작업을 수행 할 수있는 방법이 있습니까?테마가 Button 텍스트에 적용되지 않습니다.

  <Button 
      android:id="@+id/button3" 
      android:layout_width="@dimen/layout_width_numbers" 
      android:layout_height="@dimen/layout_width_numbers" 
      android:background="@drawable/numbers" 
      android:text="@string/button3" 
      android:textColor="@color/button_text_color" 
      android:textSize="@dimen/button_textsize" 
      android:textStyle="bold" /> 

업데이트 :

여기
public static void changeToTheme(Activity activity, int theme){ 
    sTheme = theme; 
    activity.finish(); 

    activity.startActivity(new Intent(activity, activity.getClass())); 
} 

/** Set the theme of the activity, according to the configuration. */ 
public static void onActivityCreateSetTheme(Activity activity){ 
    switch (sTheme) 
    { 
    default: 
    case THEME_DEFAULT: 
     activity.setTheme(R.style.FirstTheme); 
     break; 
    case THEME_WHITE: 
     activity.setTheme(R.style.SecondTheme); 
     break; 
    case THEME_BLUE: 
     activity.setTheme(R.style.ThirdTheme); 
     break; 
    } 
} 

//Shared Preferences 
public static int getTheme() 
{ 
    return sTheme; 
} 

public static boolean canSetThemeFromPrefs(final Activity activity) 
{ 
    boolean result = false; 
    SharedPreferences prefMngr = PreferenceManager.getDefaultSharedPreferences(activity); 
    if (prefMngr.contains("Theme_Preferences")) 
    { 
     result = true; 
    } 
    return result; 
} 

public static int getThemeFromPrefs(final Activity activity) 
{ 
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); 
    final String themeFromPrefs = preferences.getString("Theme_Preferences", "THEME_DEFAULT"); 
    if (themeFromPrefs.equals("THEME_BLUE")) 
    { 
     sTheme = THEME_BLUE; 
    } 
    else if (themeFromPrefs.equals("THEME_WHITE")) 
    { 
     sTheme = THEME_WHITE; 
    } 
    else 
    { 
     sTheme = THEME_DEFAULT; 
    } 

    return getTheme(); 
} 

public static int getThemeFromPrefs(final String key) 
{ 
    if (key.equals("THEME_BLUE")) 
    { 
     sTheme = THEME_BLUE; 
    } 
    else if (key.equals("THEME_WHITE")) 
    { 
     sTheme = THEME_WHITE; 
    } 
    else 
    { 
     sTheme = THEME_DEFAULT; 
    } 

    return getTheme(); 
} 

버튼입니다 : 이 내 백분율 클래스 여기

그리고는 내 Styles.xml

<!-- Change Layout theme. --> 
<!-- Red. --> 
<style name="FirstTheme" > 
    <item name="android:textColor">@color/first_theme_button</item> 
</style> 
<!-- Green. Violet --> 
<style name="SecondTheme" > 
    <item name="android:textColor">@color/second_theme_button</item> 
</style> 
<!-- Blue. --> 
<style name="ThirdTheme" > 
    <item name="android:textColor">@color/third_theme_button</item> 
</style> 

또한 공유 기본 설정이 작동하지 않으며 마지막 테마를 저장하지 않습니다 !!

감사합니다 :)

+0

사용자 정의 테마 내에서 이러한 요소에 대한 스타일을 정의하지 않았을 수 있습니까? –

+0

그래서 테마가 TextView에서 작동하고 Button이 작동하지 않는 이유는 무엇입니까? – user3051834

답변

0

나는 이것을 테스트하고, 나는 그것을 작동하게하는 방법을 알고 있다고 생각 :이했을 때, 나는 second_theme_button에서 텍스트를 편집하고 버튼을 가지고

<style name="SecondTheme" parent="android:Theme.Light"> 
    <item name="android:editTextStyle">@style/SecondTheme</item> 
    <item name="android:buttonStyle">@style/SecondTheme</item> 

    <item name="android:textColor">@color/second_theme_button</item> 
</style> 

색깔.

+0

재미있는 솔루션입니다 .. 잘 작동했습니다! 제 2의 문제로 저를 도울 수 있습니까? – user3051834

관련 문제