本文整理匯總了Java中android.app.Activity.getWindow方法的典型用法代碼示例。如果您正苦於以下問題:Java Activity.getWindow方法的具體用法?Java Activity.getWindow怎麽用?Java Activity.getWindow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.app.Activity
的用法示例。
在下文中一共展示了Activity.getWindow方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setWindowStatusBarColor
import android.app.Activity; //導入方法依賴的package包/類
/**
* 當前頁麵設置狀態欄顏色
*
* */
public static void setWindowStatusBarColor(Activity activity, int color){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
View view=contentView.getChildAt(1);
view.setBackgroundColor(color);
} else {
Window window=activity.getWindow();
if(Build.VERSION.SDK_INT>= Build.VERSION_CODES.LOLLIPOP){
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
// 狀態欄
window.setStatusBarColor(color);
// 底部導航欄
window.setNavigationBarColor(color);
}
}
}
示例2: dimBackground
import android.app.Activity; //導入方法依賴的package包/類
/**
* 調整窗口的透明度 1.0f,0.5f 變暗
*
* @param from from>=0&&from<=1.0f
* @param to to>=0&&to<=1.0f
* @param context 當前的activity
*/
public static void dimBackground(final float from, final float to, Activity context) {
final Window window = context.getWindow();
ValueAnimator valueAnimator = ValueAnimator.ofFloat(from, to);
valueAnimator.setDuration(500);
valueAnimator.addUpdateListener(
new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
WindowManager.LayoutParams params
= window.getAttributes();
params.alpha = (Float) animation.getAnimatedValue();
window.setAttributes(params);
}
});
valueAnimator.start();
}
示例3: setWindowBrightness
import android.app.Activity; //導入方法依賴的package包/類
/**
* 設置給定Activity的窗口的亮度(可以看到效果,但係統的亮度屬性不會改變)
*
* @param activity 要通過此Activity來設置窗口的亮度
* @param screenBrightness 亮度,範圍是0-255
*/
public static void setWindowBrightness(Activity activity, float screenBrightness) {
float brightness = screenBrightness;
if (screenBrightness < 1) {
brightness = 1;
} else if (screenBrightness > 255) {
brightness = screenBrightness % 255;
if (brightness == 0) {
brightness = 255;
}
}
Window window = activity.getWindow();
WindowManager.LayoutParams localLayoutParams = window.getAttributes();
localLayoutParams.screenBrightness = (float) brightness / 255;
window.setAttributes(localLayoutParams);
}
示例4: setStatusBarColor
import android.app.Activity; //導入方法依賴的package包/類
static void setStatusBarColor(Activity activity, int statusColor) {
Window window = activity.getWindow();
//取消狀態欄透明
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//添加Flag把狀態欄設為可繪製模式
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
//設置狀態欄顏色
window.setStatusBarColor(statusColor);
//設置係統狀態欄處於可見狀態
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
//讓view不根據係統窗口來調整自己的布局
ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
View mChildView = mContentView.getChildAt(0);
if (mChildView != null) {
ViewCompat.setFitsSystemWindows(mChildView, false);
ViewCompat.requestApplyInsets(mChildView);
}
}
示例5: setActivity
import android.app.Activity; //導入方法依賴的package包/類
public void setActivity(Activity activity) {
super.setActivity(activity);
int resId = getBitmapRes(activity, "ssdk_oks_shake_to_share_back");
if (resId > 0) {
activity.setTheme(android.R.style.Theme_Dialog);
activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
Window win = activity.getWindow();
win.setBackgroundDrawableResource(resId);
}
}
示例6: setStatusBarColor
import android.app.Activity; //導入方法依賴的package包/類
/**
* можем изменять цвет статус бара сверху (нужно там где его делаю прозрачным)
*
* @param colorId - собственно цвет
*/
public static void setStatusBarColor(@Nullable Activity activity, @ColorRes int colorId) {
if (activity != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = activity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(ContextCompat.getColor(activity, colorId));
}
}
示例7: setStatusBarColor
import android.app.Activity; //導入方法依賴的package包/類
/**
* 修改狀態欄顏色,支持4.4以上版本
* @param activity
* @param colorId
*/
public static void setStatusBarColor(Activity activity, int colorId) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = activity.getWindow();
// window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(activity.getResources().getColor(colorId));
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//使用SystemBarTint庫使4.4版本狀態欄變色,需要先將狀態欄設置為透明
transparencyBar(activity);
SystemBarTintManager tintManager = new SystemBarTintManager(activity);
tintManager.setStatusBarTintEnabled(true);
tintManager.setStatusBarTintResource(colorId);
}
}
示例8: setTranslucentStatus
import android.app.Activity; //導入方法依賴的package包/類
public static void setTranslucentStatus(Activity activity,int statusBarPlaceColor) {
// 5.0以上係統狀態欄透明
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = activity.getWindow();
//window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//window.setStatusBarColor(Color.TRANSPARENT);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
}
示例9: setStatusBarColor
import android.app.Activity; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void setStatusBarColor(Activity activity, int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = activity.getWindow();
if (color == 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);
}
}
示例10: tintStatusBarForDrawer
import android.app.Activity; //導入方法依賴的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);
}
示例11: setActivity
import android.app.Activity; //導入方法依賴的package包/類
public void setActivity(Activity activity) {
super.setActivity(activity);
Window win = activity.getWindow();
int orientation = activity.getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
win.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
} else {
win.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
}
}
示例12: TpSbNNbwFCImmerseMode
import android.app.Activity; //導入方法依賴的package包/類
public TpSbNNbwFCImmerseMode(@NonNull Activity activity) {
mActivityRef = new SoftReference<>(activity);
Window window = activity.getWindow();
WindowUtils.clearWindowFlags(window, FLAG_TRANSLUCENT_STATUS);
WindowUtils.clearWindowFlags(window, FLAG_TRANSLUCENT_NAVIGATION);
WindowUtils.addWindowFlags(window, FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.getDecorView().setSystemUiVisibility(SYSTEM_UI_FLAG_LAYOUT_STABLE | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
mCompatStatusBarView = setupContentViewAndStatusBarView(activity);
window.setStatusBarColor(Color.TRANSPARENT);
mCompatStatusBarView.setBackgroundColor(Color.TRANSPARENT);
}
示例13: addFakeStatusBarView
import android.app.Activity; //導入方法依賴的package包/類
/**
* 1. Add fake statusBarView.
* 2. set tag to statusBarView.
*/
private static View addFakeStatusBarView(Activity activity, int statusBarColor, int statusBarHeight) {
Window window = activity.getWindow();
ViewGroup mDecorView = (ViewGroup) window.getDecorView();
View mStatusBarView = new View(activity);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, statusBarHeight);
layoutParams.gravity = Gravity.TOP;
mStatusBarView.setLayoutParams(layoutParams);
mStatusBarView.setBackgroundColor(statusBarColor);
mStatusBarView.setTag(TAG_FAKE_STATUS_BAR_VIEW);
mDecorView.addView(mStatusBarView);
return mStatusBarView;
}
示例14: invasionStatusBar
import android.app.Activity; //導入方法依賴的package包/類
/**
* Set the content layout full the StatusBar, but do not hide StatusBar.
*/
public static void invasionStatusBar(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = activity.getWindow();
View decorView = window.getDecorView();
decorView.setSystemUiVisibility(decorView.getSystemUiVisibility()
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
}
}
示例15: setStatusBarColorForCollapsingToolbar
import android.app.Activity; //導入方法依賴的package包/類
/**
* compat for CollapsingToolbarLayout
* 1. set Window Flag : WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
* 2. set FitsSystemWindows for views.
* 3. removeFakeStatusBarViewIfExist
* 4. removeMarginTopOfContentChild
* 5. add OnOffsetChangedListener to change statusBarView's alpha
*/
public static void setStatusBarColorForCollapsingToolbar(Activity activity, final AppBarLayout appBarLayout, final CollapsingToolbarLayout collapsingToolbarLayout,
Toolbar toolbar, int statusColor) {
Window window = activity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
View mContentChild = mContentView.getChildAt(0);
mContentChild.setFitsSystemWindows(false);
((View) appBarLayout.getParent()).setFitsSystemWindows(false);
appBarLayout.setFitsSystemWindows(false);
collapsingToolbarLayout.setFitsSystemWindows(false);
collapsingToolbarLayout.getChildAt(0).setFitsSystemWindows(false);
toolbar.setFitsSystemWindows(true);
if (toolbar.getTag() == null) {
CollapsingToolbarLayout.LayoutParams lp = (CollapsingToolbarLayout.LayoutParams) toolbar.getLayoutParams();
lp.height += getStatusBarHeight(activity);
toolbar.setLayoutParams(lp);
toolbar.setTag(true);
}
int statusBarHeight = getStatusBarHeight(activity);
removeFakeStatusBarViewIfExist(activity);
removeMarginTopOfContentChild(mContentChild, statusBarHeight);
// final View statusView = addFakeStatusBarView(activity, statusColor, statusBarHeight);
// appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
// @Override
// public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
// if (Math.abs(verticalOffset) > appBarLayout.getHeight() - collapsingToolbarLayout.getStatusBarScrim().getIntrinsicHeight()) {
// if (statusView.getAlpha() == 0) {
// statusView.animate().alpha(1f).setDuration(collapsingToolbarLayout.getScrollBarFadeDuration()).start();
// }
// } else {
// statusView.setAlpha(0);
// }
// }
// });
}