How to set custom theme attribute programmatically in Android 10

Viewed 1004

It is easy to change theme attributes in styles.xml, and to define new custom theme attributes in attrs.xml.

But how to do it in java code?

After calling setTheme in Activity, how to change or define attribute programmatically?

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?
}

Thanks.

1 Answers

After doing some research, there is no way to set theme attribute programmatically.

Related