在运行时更改android主题

时间:2016-04-01 18:39:32

标签: android android-studio

我想在运行时更改Android主题,但我遇到问题:

我创造了一种新风格

{
  "base": "resources/assets/semantic",
  "paths": {
    "source": {
      "config": "src/theme.config",
      "definitions": "src/definitions/",
      "site": "src/site/",
      "themes": "src/themes/"
    },
    "output": {
      "packaged": "dist/",
      "uncompressed": "dist/components/",
      "compressed": "dist/components/",
      "themes": "dist/themes/"
    },
    "clean": "dist/"
  },
  "permission": false,
  "rtl": "No",
  "components": [
    "reset",
    "site",
    "button",
    "container",
    "divider",
    "flag",
    "header",
    "icon",
    "image",
    "input",
    "label",
    "list",
    "loader",
    "rail",
    "reveal",
    "segment",
    "step",
    "breadcrumb",
    "form",
    "grid",
    "menu",
    "message",
    "table",
    "ad",
    "card",
    "comment",
    "feed",
    "item",
    "statistic",
    "accordion",
    "checkbox",
    "dimmer",
    "dropdown",
    "embed",
    "modal",
    "nag",
    "popup",
    "progress",
    "rating",
    "search",
    "shape",
    "sidebar",
    "sticky",
    "tab",
    "transition",
    "api",
    "form",
    "state",
    "visibility"
  ],
  "version": "2.1.8"
}

并尝试在<style name="AppThemeRed" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="colorPrimary">@color/colorPrimaryRed</item> <item name="colorPrimaryDark">@color/colorPrimary</item> <item name="colorAccent">@color/colorAccentRed</item> </style> 之前使用setTheme(R.style.AppThemeRed);进行设置 但不幸的是程序关闭了。 这是日志:

setContentView(R.Layout.activity_main);

顺便说一下,我是新手并且正在学习android的开发,所以请用简单的语言回答 谢谢!

1 个答案:

答案 0 :(得分:0)

您尝试设置的主题有自己的#python 3.4 b=[1] a=b while (a[0]<10): b[0]=b[0]+1 #a=b print(a[0], b[0]) 。要获得此异常,这意味着您已在布局中指定了Toolbar视图,并将其设置在活动的某个位置。如果您这样做,请务必延长其中一个Toolbar主题,即.NoActionBar

你可能会遇到一个新问题,因为没有&#34;浅色背景 - 黑暗没有工具栏&#34; AppCompat中的主题,因此您必须自己设置工具栏的样式。

您可以看到如何在运行时切换主题的示例,还可以看到如何设置工具栏的样式,以防您在此处遇到更多问题:

Sample project

Theme declaration