public class MainStatusBarActivity extends AppCompatActivity {
public WindowInfo windowInfo;
@TargetApi(Build.VERSION_CODES.KITKAT)
@SuppressLint("InlinedApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
windowInfo = new WindowInfo(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window window = getWindow();
// Translucent status bar
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
}
public void initStatebar() {
View title_bar_public = findViewById(R.id.statebar);
int height = windowInfo.getStatusBarHeight();
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, height);
title_bar_public.setLayoutParams(params);
forKitkatOrBigger(title_bar_public, params);
}
public void forKitkatOrBigger(View view, LayoutParams params) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
view.setLayoutParams(params);
view.setBackgroundResource(R.color.view_back);
view.setVisibility(View.VISIBLE);
}
}
}
public WindowInfo windowInfo;
@TargetApi(Build.VERSION_CODES.KITKAT)
@SuppressLint("InlinedApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
windowInfo = new WindowInfo(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window window = getWindow();
// Translucent status bar
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
}
public void initStatebar() {
View title_bar_public = findViewById(R.id.statebar);
int height = windowInfo.getStatusBarHeight();
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, height);
title_bar_public.setLayoutParams(params);
forKitkatOrBigger(title_bar_public, params);
}
public void forKitkatOrBigger(View view, LayoutParams params) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
view.setLayoutParams(params);
view.setBackgroundResource(R.color.view_back);
view.setVisibility(View.VISIBLE);
}
}
}