테마 클래스가 "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>
또한 공유 기본 설정이 작동하지 않으며 마지막 테마를 저장하지 않습니다 !!
감사합니다 :)
사용자 정의 테마 내에서 이러한 요소에 대한 스타일을 정의하지 않았을 수 있습니까? –
그래서 테마가 TextView에서 작동하고 Button이 작동하지 않는 이유는 무엇입니까? – user3051834