本文整理汇总了Java中android.view.Window.findViewById方法的典型用法代码示例。如果您正苦于以下问题:Java Window.findViewById方法的具体用法?Java Window.findViewById怎么用?Java Window.findViewById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.Window
的用法示例。
在下文中一共展示了Window.findViewById方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: show
import android.view.Window; //导入方法依赖的package包/类
public AlertDialog show(Context context) {
dialog = new AlertDialog.Builder(context).create();
dialog.show();
Window window = dialog.getWindow();
window.setContentView(R.layout.dialog_date_time);
window.setGravity(Gravity.CENTER);// 此处可以设置dialog显示的位置
//window.setWindowAnimations(R.style.in_left_out_right_style);
window.setBackgroundDrawableResource(R.color.transparent);
datePicker = (DatePicker) window
.findViewById(R.id.date_time_datePicker1);
datePicker.setCalendarViewShown(false);
timePicker = (TimePicker) window.findViewById(R.id.date_time_timePicker);
but_ok = (Button) window.findViewById(R.id.date_time_but_ok);
but_ok.setOnClickListener(this);
return dialog;
}
示例2: setStatusBarColor
import android.view.Window; //导入方法依赖的package包/类
/**
* set StatusBarColor
* <p>
* 1. set Flags to call setStatusBarColor
* 2. call setSystemUiVisibility to clear translucentStatusBar's Flag.
* 3. set FitsSystemWindows to false
*/
static void setStatusBarColor(Activity activity, int statusColor, boolean isLight) {
Window window = activity.getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(statusColor);
int options = View.SYSTEM_UI_FLAG_VISIBLE;
if (isLight) {
options = options | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
}
window.getDecorView().setSystemUiVisibility(options);
ViewGroup contentview = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
View childview = contentview.getChildAt(0);
if (childview != null) {
childview.setFitsSystemWindows(false);
childview.requestApplyInsets();
}
}
示例3: setStatusBarColor
import android.view.Window; //导入方法依赖的package包/类
/**
* set StatusBarColor
* <p>
* 1. set Window Flag : WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
* 2. removeFakeStatusBarViewIfExist
* 3. addFakeStatusBarView
* 4. addMarginTopToContentChild
* 5. cancel ContentChild's fitsSystemWindow
*/
static void setStatusBarColor(Activity activity, int statusColor) {
Window window = activity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
ViewGroup contentview = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
View contentchild = contentview.getChildAt(0);
int statusBarHeight = getStatusBarHeight(activity);
removeFakeStatusBarViewIfExist(activity);
addFakeStatusBarView(activity, statusColor, statusBarHeight);
addMarginTopToContentChild(contentchild, statusBarHeight);
if (contentchild != null) {
contentchild.setFitsSystemWindows(false);
}
}
示例4: setStatusBarColor
import android.view.Window; //导入方法依赖的package包/类
/**
* set StatusBarColor
* 1. set Window Flag : WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
* 2. removeFakeStatusBarViewIfExist
* 3. addFakeStatusBarView
* 4. addMarginTopToContentChild
* 5. cancel ContentChild's fitsSystemWindow
*/
public static void setStatusBarColor(Activity activity, 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);
int statusBarHeight = getStatusBarHeight(activity);
removeFakeStatusBarViewIfExist(activity);
addFakeStatusBarView(activity, statusColor, statusBarHeight);
addMarginTopToContentChild(mContentChild, statusBarHeight);
if (mContentChild != null) {
ViewCompat.setFitsSystemWindows(mContentChild, false);
}
}
示例5: setStatusBarColorForCollapsingToolbar
import android.view.Window; //导入方法依赖的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);
// }
// }
// });
}
示例6: onCreate
import android.view.Window; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
getDelegate().setContentView(R.layout.activity_base);
Window window = getWindow();
requestState = (TextView) window.findViewById(R.id.requestState);
requestHeaders = (TextView) window.findViewById(R.id.requestHeaders);
responseData = (TextView) window.findViewById(R.id.responseData);
responseHeader = (TextView) window.findViewById(R.id.responseHeader);
rootContent = (FrameLayout) window.findViewById(R.id.content);
onActivityCreate(savedInstanceState);
}
示例7: showDialog
import android.view.Window; //导入方法依赖的package包/类
@Override
protected void showDialog(Bundle state)
{
super.showDialog(state);
final Resources res = getContext().getResources();
final Window window = getDialog().getWindow();
final int color = res.getColor(themeManager.getColorTheme(getContext()));
// Title
final int titleId = res.getIdentifier("alertTitle", "id", "android");
final View title = window.findViewById(titleId);
if (title != null)
{
((TextView) title).setTextColor(color);
}
// Title divider
final int titleDividerId = res.getIdentifier("titleDivider", "id", "android");
final View titleDivider = window.findViewById(titleDividerId);
if (titleDivider != null)
{
titleDivider.setBackgroundColor(color);
}
}
示例8: updateSoftInputWindowLayoutParameters
import android.view.Window; //导入方法依赖的package包/类
private void updateSoftInputWindowLayoutParameters() {
// Override layout parameters to expand {@link SoftInputWindow} to the entire screen.
// See {@link InputMethodService#setinputView(View)} and
// {@link SoftInputWindow#updateWidthHeight(WindowManager.LayoutParams)}.
final Window window = getWindow().getWindow();
ViewLayoutUtils.updateLayoutHeightOf(window, LayoutParams.MATCH_PARENT);
// This method may be called before {@link #setInputView(View)}.
if (mInputView != null) {
// In non-fullscreen mode, {@link InputView} and its parent inputArea should expand to
// the entire screen and be placed at the bottom of {@link SoftInputWindow}.
// In fullscreen mode, these shouldn't expand to the entire screen and should be
// coexistent with {@link #mExtractedArea} above.
// See {@link InputMethodService#setInputView(View) and
// com.android.internal.R.layout.input_method.xml.
final int layoutHeight = isFullscreenMode()
? LayoutParams.WRAP_CONTENT : LayoutParams.MATCH_PARENT;
final View inputArea = window.findViewById(android.R.id.inputArea);
ViewLayoutUtils.updateLayoutHeightOf(inputArea, layoutHeight);
ViewLayoutUtils.updateLayoutGravityOf(inputArea, Gravity.BOTTOM);
ViewLayoutUtils.updateLayoutHeightOf(mInputView, layoutHeight);
}
}
示例9: getStatusBarHeight
import android.view.Window; //导入方法依赖的package包/类
public static int getStatusBarHeight(Activity activity) {
int result = 0;
Rect rect = new Rect();
Window window = activity.getWindow();
if (window != null) {
window.getDecorView().getWindowVisibleDisplayFrame(rect);
View v = window.findViewById(Window.ID_ANDROID_CONTENT);
android.view.Display display = ((android.view.WindowManager) activity.getSystemService(activity.WINDOW_SERVICE)).getDefaultDisplay();
//return result title bar height
int result1 = display.getHeight() - v.getBottom() + rect.top;
int result2 = display.getHeight() - v.getBottom();
int result3 = v.getTop() - rect.top;
int result4 = display.getHeight() - v.getHeight();
Log.e("StatusBarHeight==", "result1== " + result1 +" result2 = " + result2 + "result3=" + result3 + "result4=" +result4 ) ;
}
return result;
}
示例10: setStatusBarColor
import android.view.Window; //导入方法依赖的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);
}
}
示例11: translucentStatusBar
import android.view.Window; //导入方法依赖的package包/类
static void translucentStatusBar(Activity activity, boolean hideStatusBarBackground) {
Window window = activity.getWindow();
//添加Flag把状态栏设为可绘制模式
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
if (hideStatusBarBackground) {
//如果为全透明模式,取消设置Window半透明的Flag
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//设置状态栏为透明
window.setStatusBarColor(Color.TRANSPARENT);
//设置window的状态栏不可见
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
} else {
//如果为半透明模式,添加设置Window半透明的Flag
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//设置系统状态栏处于可见状态
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);
}
}
示例12: setStatusBarColor
import android.view.Window; //导入方法依赖的package包/类
static void setStatusBarColor(Activity activity, int statusColor) {
Window window = activity.getWindow();
//设置Window为全透明
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
//获取父布局
View mContentChild = mContentView.getChildAt(0);
//获取状态栏高度
int statusBarHeight = getStatusBarHeight(activity);
//如果已经存在假状态栏则移除,防止重复添加
removeFakeStatusBarViewIfExist(activity);
//添加一个View来作为状态栏的填充
addFakeStatusBarView(activity, statusColor, statusBarHeight);
//设置子控件到状态栏的间距
addMarginTopToContentChild(mContentChild, statusBarHeight);
//不预留系统栏位置
if (mContentChild != null) {
ViewCompat.setFitsSystemWindows(mContentChild, false);
}
//如果在Activity中使用了ActionBar则需要再将布局与状态栏的高度跳高一个ActionBar的高度,否则内容会被ActionBar遮挡
int action_bar_id = activity.getResources().getIdentifier("action_bar", "id", activity.getPackageName());
View view = activity.findViewById(action_bar_id);
if (view != null) {
TypedValue typedValue = new TypedValue();
if (activity.getTheme().resolveAttribute(R.attr.actionBarSize, typedValue, true)) {
int actionBarHeight = TypedValue.complexToDimensionPixelSize(typedValue.data, activity.getResources().getDisplayMetrics());
Eyes.setContentTopPadding(activity, actionBarHeight);
}
}
}
示例13: setFitSystemWindows
import android.view.Window; //导入方法依赖的package包/类
/**
* 注意不是设置ContentView的FitsSystemWindows, 而是设置ContentView的第一个子 View
* 预留出系统 View 的空间。
* 设置ContentView的FitsSystemWindows,Toast显示不正常,它的文字会超出黑色背景之外。
*
* @param fitSystemWindows
*/
public void setFitSystemWindows(boolean fitSystemWindows) {
Window window = activity.getWindow();
ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
View mChildView = mContentView.getChildAt(0);
if (mChildView != null) {
mChildView.setFitsSystemWindows(fitSystemWindows);
}
}
示例14: setStatusBarColorForCollapsingToolbar
import android.view.Window; //导入方法依赖的package包/类
/**
* compat for CollapsingToolbarLayout
*/
public static void setStatusBarColorForCollapsingToolbar(Activity activity, final AppBarLayout appBarLayout, CollapsingToolbarLayout collapsingToolbarLayout,
Toolbar toolbar, int statusColor) {
Window window = activity.getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
View mChildView = mContentView.getChildAt(0);
if (mChildView != null) {
ViewCompat.setOnApplyWindowInsetsListener(mChildView, new OnApplyWindowInsetsListener() {
@Override
public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
return insets;
}
});
ViewCompat.setFitsSystemWindows(mChildView, true);
ViewCompat.requestApplyInsets(mChildView);
}
((View) appBarLayout.getParent()).setFitsSystemWindows(true);
appBarLayout.setFitsSystemWindows(true);
collapsingToolbarLayout.setFitsSystemWindows(true);
collapsingToolbarLayout.getChildAt(0).setFitsSystemWindows(true);
toolbar.setFitsSystemWindows(false);
collapsingToolbarLayout.setStatusBarScrimColor(statusColor);
}
示例15: showDialog
import android.view.Window; //导入方法依赖的package包/类
@Override
protected void showDialog(Bundle state) {
super.showDialog(state);
final Resources res = getContext().getResources();
final Window window = getDialog().getWindow();
Button button1 = (Button) window.findViewById(res.getIdentifier("button1", "id", "android"));
Button button2 = (Button) window.findViewById(res.getIdentifier("button2", "id", "android"));
button1.setTextColor(res.getColor(R.color.black));
button2.setTextColor(res.getColor(R.color.black));
}