Use uncompiled theme

Is it possible to create, Themeinstead of a limited number of themes, precompiled (which means how the OS sent the themes and xml resource)? The theme will be applied at application startup time based on the user configuration (the values ​​change at runtime, but before the stylized activity is created, the values ​​come from http services from a large range, not from a set).

Any other solution is welcome until it requires the use of custom View classes everywhere.

Now I need to set the default text color for the default text text, and of course I don’t want to use a subclass everywhere, I think that there is no huge disaster from the loss of optimization, or at least it would be great to see a performance difference.

+5
source share
2 answers

Well, that might be too bad, but here's a shot.

public class BaseActivity extends Activity{

    @Override
    public void onResume() {
        ViewGroup root = ((ViewGroup)findViewById(android.R.id.content));
        applyTheme(root);
    }

    private void applyTheme(View view){
        if (view instanceof ViewGroup && ((ViewGroup) view).getChildCount() !=0){
            for (int i = 0; i< ((ViewGroup) view).getChildCount(); i++){
                applyTheme(((ViewGroup) view).getChildAt(i));
            }
        } else {
            if (view instanceof TextView){
                ((TextView) view).setTextColor(your_color_from_server_here);
            }
        }
    }
}

And all your actions extend BaseActivity.

+1
source

Override ContextThemeWrapper.getTheme () in your activity and provide your own Theme .

Or apply the predefined theme in Activity.onCreate before calling super.onCreate, providing a custom theme resource identifier:

@Override
public void onCreate(Bundle si){
   setTheme(R.style.MyTheme);
   super.onCreate(si);
}

xml . . .xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <style name="MyTheme" parent="android:Theme.Holo">
      <item name="android:textColorPrimary">#0f0</item>
   </style>
</resources>

, .

+1

All Articles