简体   繁体   中英

How to set custom theme attribute programmatically in Android 10

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM