android - 如何以编程方式更改应用程序的 colorPrimary 、 colorPrimaryDark 和 colorAccent

标签 android

是否有可能以编程方式覆盖 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/

相关文章:

android - 图形 API 在 Android 中无法正常工作

android - Android 上的 GridView 错误

android - 如何在摩托罗拉里程碑,android中获取屏幕宽度和高度

java - Android继续循环动画

android - 图标到边缘

java - android recyclerview 仅在第一次显示数据

android - 支持库 23.2.0 的 NavigationView 奇怪间距

android - 更改editText提示的字体

Android日期选择器示例 : DatePickerDialog. OnDateSetListener(){} 必须实现继承的抽象方法onDateSet

android - 使用 Android 的 Algolia 和 Cloud Firestore?