如何在buttonclick上調用setStatusBarColor?我有事件監聽器代碼,但我不確定如何調用此方法。我試圖在點擊按鈕時更改狀態欄的顏色。調用setStatusBarColor ANDROID
這裏是我的代碼:
public static void setStatusBarColor(Activity activity, int statusBarColor) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// If both system bars are black, we can remove these from our layout,
// removing or shrinking the SurfaceFlinger overlay required for our views.
Window window = activity.getWindow();
if (statusBarColor == Color.BLACK && window.getNavigationBarColor() == Color.BLACK) {
window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
} else {
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
}
window.setStatusBarColor(Color.parseColor("#4CAF50"));
}
}
這裏是我的按鈕偵聽
public void addButtonListener() {
Button = (Button) findViewById(R.id.Button);
Button.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
setStatusBarColor();
}
});
}
你能解釋一下什麼是不工作的參數? – 2015-03-13 14:28:27
在您的按鈕上至少顯示偵聽器代碼。 – 2015-03-13 14:31:57
道歉@ci_。我試圖用setStatusBarColor()來調用它。 – user1353517 2015-03-13 14:50:04