android - Get the Theme value applied for an activity programmatically -


I want to know which themes are implemented for any activity in an app.

Normally we are setting the theme by using

  settheme (android.r.style.Theme_Light);   

Here we are specifying style, such that we may be able to achieve a specific type of style for an activity in the program.

Thanks

called getThemeResId in the reference class There is a good method, although it is private so you need to use the reflection. / P>

Here's an example:

  @ override protected form zero (bundle savedinstenstate) {super.New (savedinstenstate); SetContentView (R.layout.activity_my); Logs. E ("tag", "def theme:" + R. style. Aaptim); Logs. E ("tag", "light theme:" + android.r.style.me_Light); Logs. E ("tag", "current theme id:" + receivedTheme ()); SetTheme (android.R.style.Theme_Light); Logs. E ("tag", "current theme id:" + receivedTheme ()); } Int getThemeId () {try {class & lt ;? & Gt; Wrapper = Context.class; Method method = wrapper.getMethod ("getThemeResId"); Method.setAccessible (true); Return (integer) method.invoke (this); } Hold (exception e) {e.printStackTrace (); } Return 0; }    

Comments

Popular posts from this blog

Out of index C/C++ -

regex - PatternSyntaxException: while using String.ReplaceAll function in java? -

java - Projects which are accessed via multiple (different) IDEs: Ant or Maven? -