本文整理匯總了Java中android.support.v4.widget.DrawerLayout.setStatusBarBackgroundColor方法的典型用法代碼示例。如果您正苦於以下問題:Java DrawerLayout.setStatusBarBackgroundColor方法的具體用法?Java DrawerLayout.setStatusBarBackgroundColor怎麽用?Java DrawerLayout.setStatusBarBackgroundColor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v4.widget.DrawerLayout
的用法示例。
在下文中一共展示了DrawerLayout.setStatusBarBackgroundColor方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: tintStatusBarForDrawer
import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
/**
* Android4.4以上的狀態欄著色(針對於DrawerLayout)
* 注:
* 1.如果出現界麵展示不正確,刪除布局中所有fitsSystemWindows屬性,尤其是DrawerLayout的fitsSystemWindows屬性
* 2.可以版本判斷在5.0以上不調用該方法,使用係統自帶
*
* @param activity Activity對象
* @param drawerLayout DrawerLayout對象
* @param statusBarColor 狀態欄顏色
* @param alpha 透明欄透明度[0.0-1.0]
*/
public static void tintStatusBarForDrawer(Activity activity, DrawerLayout drawerLayout,
@ColorInt int statusBarColor,
@FloatRange(from = 0.0, to = 1.0) float alpha) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
return;
}
Window window = activity.getWindow();
ViewGroup decorView = (ViewGroup) window.getDecorView();
ViewGroup drawContent = (ViewGroup) drawerLayout.getChildAt(0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
drawerLayout.setStatusBarBackgroundColor(statusBarColor);
int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
window.getDecorView().setSystemUiVisibility(systemUiVisibility);
} else {
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
setStatusBar(decorView, statusBarColor, true, true);
setTranslucentView(decorView, alpha);
drawerLayout.setFitsSystemWindows(false);
drawContent.setFitsSystemWindows(true);
ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
drawer.setFitsSystemWindows(false);
}