相关疑难解决方法(0)

动态设置主题颜色

我在我的Android应用程序中使用主题(动态),如下所示:

my_layout.xml(提取):

<TextView
    android:id="@+id/myItem"
    style="?my_item_style" />
Run Code Online (Sandbox Code Playgroud)

attrs.xml(提取):

<attr name="my_item_style" format="reference" />
Run Code Online (Sandbox Code Playgroud)

themes.xml(提取):

<style name="MainTheme.Blue">
      <item name="my_item_style">@style/my_item_style_blue</item>
</style>

<style name="MainTheme.Green">
      <item name="my_item_style">@style/my_item_style_green<item>
</style>
Run Code Online (Sandbox Code Playgroud)

styles.xml(提取):

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

<style name="my_item_style_green">
      <item name="android:textColor">@color/my_blue</item>
</style>
Run Code Online (Sandbox Code Playgroud)

所以,正如你所看到的,我正在动态设置主题.我正在使用这堂课:

public class ThemeUtils {

  private static int sTheme;
  public final static int THEME_BLUE = 1;
  public final static int THEME_GREEN = 2;

  public static void changeToTheme(MainActivity activity, int theme) {
      sTheme = theme;
      activity.startActivity(new Intent(activity, MyActivity.class));
  }

  public static void onActivityCreateSetTheme(Activity activity) …
Run Code Online (Sandbox Code Playgroud)

android themes colors android-activity

9
推荐指数
1
解决办法
7948
查看次数

标签 统计

android ×1

android-activity ×1

colors ×1

themes ×1