如何在 Android 10 中以编程方式设置自定义主题属性

How to set custom theme attribute programmatically in Android 10

在 styles.xml 中更改主题属性很容易,在 attrs.xml 中定义新的自定义主题属性也很容易。

但是在java代码中如何做到呢?

在 Activity 中调用 setTheme 后,如何以编程方式更改或定义属性?

TestActivity.java

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

    // Apply "AppTheme" to this Activity
    super.setTheme(R.style.AppTheme);

    // How to change theme attribute "colorPrimary" or "android.R.attr.colorPrimary" in here?

    // How to define new custom theme attribute "customThemeAttribute" in here?
}

谢谢。

经过一些研究,无法以编程方式设置主题属性。