public ViewGroup getActionBar(View view) { try { if (view instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view; if (viewGroup instanceof android.support.v7.widget.Toolbar) { return viewGroup; } for (int i = 0; i < viewGroup.getChildCount(); i++) { ViewGroup actionBar = getActionBar(viewGroup.getChildAt(i)); if (actionBar != null) { return actionBar; } } } } catch (Exception e) { } return null;}
ViewGroup actionBar = getActionBar(getWindow().getDecorView());actionBar.setBackgroundResource(R.color.colorAccent);
获得根视图
decorView = (ViewGroup) getWindow().getDecorView().findViewById(android.R.id.content);