是否有可能以编程方式覆盖 colorPrimary、colorPrimaryDark 和 colorAccent
值,并在运行时从 java 代码相应地进行更改?如果可能请帮忙。
最佳答案
不,这不可能。但是您可以创建多个样式并在运行时更改 Activity 使用的样式。为此,请在调用 setContentView()
之前使用 setTheme()
并在 onCreate()
中调用 super.onCreate()
方法> Activity 方法!
public void onCreate(Bundle savedInstanceState) {
setTheme(R.style.MyTheme); // (for Custom theme)
super.onCreate(savedInstanceState);
this.setContentView(R.layout.myactivity);
}
关于android - 如何以编程方式更改应用程序的 colorPrimary 、 colorPrimaryDark 和 colorAccent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41257939/