Android 如何更改活动';在运行时使用styles.xml创建主题

Android 如何更改活动';在运行时使用styles.xml创建主题,android,android-activity,android-xml,android-theme,Android,Android Activity,Android Xml,Android Theme,style.xml中有3种不同类型的样式,如下所示: <style name="Theme_A" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="colorPrimary">#01AC50</item> <item name="colorPrimaryDark>#FF007838</item> <item name="colorAccent

style.xml
中有3种不同类型的样式,如下所示:

<style name="Theme_A" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">#01AC50</item>
    <item name="colorPrimaryDark>#FF007838</item>
    <item name="colorAccent">#009688</item>"
<style>

#01AC50
试试这个:-

您需要在
setContentView()之前使用
setTheme()
函数

正如doc所说,在视图实例化之前,您需要定义主题

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

     setTheme(android.R.style.Theme_Dark);
     .
     .
     setContentView(R.layout.main);
}
有没有建议使用

也就是说:在
setTheme
之后,似乎需要
setContentView

在上下文中实例化任何视图之前,应调用[
setTheme
]

setContentView(...);
setTheme(R.style.MyTheme);
setContentView(...);