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);
得到根視圖android
decorView = (ViewGroup) getWindow().getDecorView().findViewById(android.R.id.content);