android.view.Window#findViewById ( )源码实例Demo

下面列出了android.view.Window#findViewById ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: AOSP-Kayboard-7.1.2   文件: LatinIME.java
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);
    }
}
 
源代码2 项目: Common   文件: StatusBarCompatKitKat.java
/**
 * 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 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);
    }
}
 
源代码3 项目: Android-Keyboard   文件: LatinIME.java
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);
    }
}
 
源代码4 项目: Android-utils   文件: BarUtils.java
private static View applyStatusBarColor(final Window window,
                                        final int color,
                                        boolean isDecor) {
    ViewGroup parent = isDecor ?
            (ViewGroup) window.getDecorView() :
            (ViewGroup) window.findViewById(android.R.id.content);
    View fakeStatusBarView = parent.findViewWithTag(TAG_STATUS_BAR);
    if (fakeStatusBarView != null) {
        if (fakeStatusBarView.getVisibility() == View.GONE) {
            fakeStatusBarView.setVisibility(View.VISIBLE);
        }
        fakeStatusBarView.setBackgroundColor(color);
    } else {
        fakeStatusBarView = createStatusBarView(window.getContext(), color);
        parent.addView(fakeStatusBarView);
    }
    return fakeStatusBarView;
}
 
源代码5 项目: weex   文件: ScreenShot.java
public static  int getStatusBarHeight(Activity activity) {
    int result = 0;
    Rect rect = new Rect();
    Window window = activity.getWindow();
    if (window != null) {
        window.getDecorView().getWindowVisibleDisplayFrame(rect);
        android.view.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;

}
 
源代码6 项目: MeiBaseModule   文件: EyesLollipop.java
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);
    }
}
 
源代码7 项目: wallpaper   文件: FeedbackActivity.java
public void tianjia_click(View v) {
	dialog = new Dialog(this, R.style.Transparent);
	dialog.setContentView(R.layout.zdy_style);

	Window dialogWindow = dialog.getWindow();
	WindowManager.LayoutParams lp = dialogWindow.getAttributes();
	WindowManager wm = (WindowManager) FeedbackActivity.this.getSystemService(Context.WINDOW_SERVICE);
	int width = wm.getDefaultDisplay().getWidth();
	int height = wm.getDefaultDisplay().getHeight();
	lp.x = 0;
	lp.y = 0;
	lp.width = width;
	lp.height = height;
	lp.alpha = 0.7f;

	TextView textView1_quxiao = (TextView) dialogWindow.findViewById(R.id.textView1_quxiao);
	textView1_quxiao.setOnClickListener(this);
	TextView textView2_paizhao = (TextView) dialogWindow.findViewById(R.id.textView2_paizhao);
	textView2_paizhao.setOnClickListener(this);
	mImageView = (ImageView) dialogWindow.findViewById(R.id.imageView3_phone);
	dialog.show();
}
 
源代码8 项目: wallpaper   文件: FeedbackActivity.java
public void tianjia_click(View v) {
	dialog = new Dialog(this, R.style.Transparent);
	dialog.setContentView(R.layout.zdy_style);

	Window dialogWindow = dialog.getWindow();
	WindowManager.LayoutParams lp = dialogWindow.getAttributes();
	WindowManager wm = (WindowManager) FeedbackActivity.this.getSystemService(Context.WINDOW_SERVICE);
	int width = wm.getDefaultDisplay().getWidth();
	int height = wm.getDefaultDisplay().getHeight();
	lp.x = 0;
	lp.y = 0;
	lp.width = width;
	lp.height = height;
	lp.alpha = 0.7f;

	TextView textView1_quxiao = (TextView) dialogWindow.findViewById(R.id.textView1_quxiao);
	textView1_quxiao.setOnClickListener(this);
	TextView textView2_paizhao = (TextView) dialogWindow.findViewById(R.id.textView2_paizhao);
	textView2_paizhao.setOnClickListener(this);
	mImageView = (ImageView) dialogWindow.findViewById(R.id.imageView3_phone);
	dialog.show();
}
 
源代码9 项目: AndroidUtilCode   文件: BarUtils.java
private static View applyStatusBarColor(final Window window,
                                        final int color,
                                        boolean isDecor) {
    ViewGroup parent = isDecor ?
            (ViewGroup) window.getDecorView() :
            (ViewGroup) window.findViewById(android.R.id.content);
    View fakeStatusBarView = parent.findViewWithTag(TAG_STATUS_BAR);
    if (fakeStatusBarView != null) {
        if (fakeStatusBarView.getVisibility() == View.GONE) {
            fakeStatusBarView.setVisibility(View.VISIBLE);
        }
        fakeStatusBarView.setBackgroundColor(color);
    } else {
        fakeStatusBarView = createStatusBarView(window.getContext(), color);
        parent.addView(fakeStatusBarView);
    }
    return fakeStatusBarView;
}
 
源代码10 项目: Common   文件: StatusBarCompatLollipop.java
/**
 * translucentStatusBar(full-screen)
 * <p>
 * 1. set Flags to full-screen
 * 2. set FitsSystemWindows to false
 *
 * @param hideStatusBarBackground hide statusBar's shadow
 */
static void translucentStatusBar(Activity activity, boolean hideStatusBarBackground) {
    Window window = activity.getWindow();

    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    if (hideStatusBarBackground) {
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.setStatusBarColor(Color.TRANSPARENT);
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    } else {
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        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.setFitsSystemWindows(mChildView, false);
        ViewCompat.requestApplyInsets(mChildView);
    }
}
 
源代码11 项目: QPM   文件: StatusBarColorUtils.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private static void setStatusBarColorLollipop(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) {
        mChildView.setFitsSystemWindows(false);
        ViewCompat.requestApplyInsets(mChildView);
    }
}
 
源代码12 项目: Indic-Keyboard   文件: LatinIME.java
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);
    }
}
 
源代码13 项目: DevUtils   文件: BarUtils.java
/**
 * 应用 StatusBar View
 * @param window  {@link Window}
 * @param color   背景颜色
 * @param isDecor 是否添加在 DecorView 上
 * @return StatusBar View
 */
private static View applyStatusBarColor(final Window window, final int color, final boolean isDecor) {
    if (window == null) return null;
    ViewGroup parent = isDecor ? (ViewGroup) window.getDecorView() : (ViewGroup) window.findViewById(android.R.id.content);
    View fakeStatusBarView = parent.findViewWithTag(TAG_STATUS_BAR);
    if (fakeStatusBarView != null) {
        if (fakeStatusBarView.getVisibility() == View.GONE) {
            fakeStatusBarView.setVisibility(View.VISIBLE);
        }
        fakeStatusBarView.setBackgroundColor(color);
    } else {
        fakeStatusBarView = createStatusBarView(window.getContext(), color);
        parent.addView(fakeStatusBarView);
    }
    return fakeStatusBarView;
}
 
@Override
protected void onInitView(@NonNull Window window) {
    window.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    mStorageList = (RecyclerView) window.findViewById(R.id.list);
    mStorageList.setLayoutManager(new LinearLayoutManager(getContext()));
    List<StorageHacker.StorageInfo> empty = new ArrayList<>(6);
    mAdapter = new PerformanceViewAdapter(getContext(), empty);
    mStorageList.setAdapter(mAdapter);
}
 
源代码15 项目: ticdesign   文件: AlertController.java
public void setup(Window window,
                  @IdRes int textButtonId, @IdRes int textSpaceId,
                  @IdRes int iconButtonId) {
    textButton = (Button) window.findViewById(textButtonId);
    textSpace = (Space) window.findViewById(textSpaceId);
    iconButton = (FloatingActionButton) window.findViewById(iconButtonId);
}
 
源代码16 项目: MeiBaseModule   文件: EyesKitKat.java
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);
        }
    }
}
 
源代码17 项目: status-bar-compat   文件: StatusBarCompat.java
public static void resetActionBarContainerTopMargin(Window window) {
    View contentView = window.findViewById(android.R.id.content);
    ViewGroup group = (ViewGroup) contentView.getParent();
    if (group.getChildCount() > 1) {
        View view = group.getChildAt(1);
        internalResetActionBarContainer(view);
    }
}
 
@Override
public void onStart() {
    super.onStart();
    // Need to do this here, since getDialog() returns null in for example onBindDialogView()
    final Resources res = getContext().getResources();
    final Window window = getDialog().getWindow();
    Button button1 = window.findViewById(android.R.id.button1);
    Button button2 = window.findViewById(android.R.id.button2);
    button1.setTextColor(res.getColor(R.color.black));
    button2.setTextColor(res.getColor(R.color.black));
}
 
源代码19 项目: Awesome-WanAndroid   文件: CommonAlertDialog.java
/**
 * Show alertDialog
 *
 * @param mActivity activity instance
 * @param content show content
 * @param btnContent btn content
 */
public void showDialog(Activity mActivity, String content, String btnContent) {
    if (mActivity == null) {
        return;
    }
    if (alertDialog == null) {
        alertDialog = new AlertDialog.Builder(mActivity, R.style.myCorDialog).create();
    }
    if (!alertDialog.isShowing()) {
        alertDialog.show();
    }
    alertDialog.setCanceledOnTouchOutside(false);
    Window window = alertDialog.getWindow();
    if (window != null) {
        window.setContentView(R.layout.common_alert_dialog);
        TextView contentTv = (TextView) window.findViewById(R.id.dialog_content);
        contentTv.setText(content);
        Button mOkBtn = (Button) window.findViewById(R.id.dialog_btn);
        mOkBtn.setText(btnContent);
        mOkBtn.setOnClickListener(v -> {
            if (alertDialog != null) {
                alertDialog.cancel();
                alertDialog = null;
            }
        });
        View btnDivider = window.findViewById(R.id.dialog_btn_divider);
        btnDivider.setVisibility(View.GONE);
        Button mNeBtn = (Button) window.findViewById(R.id.dialog_negative_btn);
        mNeBtn.setVisibility(View.GONE);
    }
}
 
源代码20 项目: Pas   文件: GetViewById.java
/**
 * Activity
 * @param view
 * @param viewId
 * @param <T>
 * @return
 */
public static <T> T $(Window view,int viewId) {
    return (T) view.findViewById(viewId);
}