Android 主题不';t应用于按钮';s文本
我有一个主题类“Util”,我有3个按钮来更改活动中的主题。 当我应用主题时,everyTextView与主题配合良好,EditText不起作用,这使我将其更改为TextView,按钮也不起作用。 我发现文本颜色字段必须是空的,就像在TextView中一样。 我把我的按钮改成了文本视图,它工作了!但有没有办法让这些按钮也能正常工作?? 这是我的Util类:Android 主题不';t应用于按钮';s文本,android,button,themes,Android,Button,Themes,我有一个主题类“Util”,我有3个按钮来更改活动中的主题。 当我应用主题时,everyTextView与主题配合良好,EditText不起作用,这使我将其更改为TextView,按钮也不起作用。 我发现文本颜色字段必须是空的,就像在TextView中一样。 我把我的按钮改成了文本视图,它工作了!但有没有办法让这些按钮也能正常工作?? 这是我的Util类: public static void changeToTheme(Activity activity, int theme){
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();
}
这是我的按钮:
<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" />
更新:
<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" />
这是我的style.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>
@颜色/第一个主题按钮
@颜色/第二个主题按钮
@颜色/第三个主题按钮
而且共享首选项不起作用,也无法保存我的上一个主题
谢谢:)我已经测试过了,我想我知道如何让它工作:
<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>
@风格/第二主题
@风格/第二主题
@颜色/第二个主题按钮
当我这样做的时候,我在
第二个主题按钮中得到了编辑文本和按钮。
颜色。有没有可能在自定义主题中没有为这些元素定义样式?那么为什么主题使用TextView而不使用按钮?这是一个有趣的解决方案。。它确实工作得很好!!你能帮我解决第二个问题吗?