-
-
Save mkawserm/3dea7775739080d4e7cb182b56262d4e to your computer and use it in GitHub Desktop.
add ImageView to Status Bar, Transparrent Status Bar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add background image to Status Bar android | |
private void setStatusBar(Activity activity, int imageRes) { | |
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { | |
return; | |
} | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | |
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); | |
activity.getWindow().setStatusBarColor(Color.TRANSPARENT); | |
} else { | |
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | |
} | |
ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0); | |
rootView.setFitsSystemWindows(true); | |
rootView.setClipToPadding(true); | |
ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content); | |
if (contentView.getChildCount() > 1) { | |
contentView.removeViewAt(1); | |
} | |
int res = activity.getResources().getIdentifier("status_bar_height", "dimen", "android"); | |
int height = 0; | |
if (res != 0) | |
height = activity.getResources().getDimensionPixelSize(res); | |
ImageView image = new ImageView(activity); | |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height); | |
image.setLayoutParams(params); | |
image.setImageResource(imageRes); | |
image.setScaleType(ScaleType.MATRIX); | |
contentView.addView(image); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment