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.