Java中android.app.Activity.getWindowManager方法 用法示例代码

您所在的位置:网站首页 getrealmetrics Java中android.app.Activity.getWindowManager方法 用法示例代码

Java中android.app.Activity.getWindowManager方法 用法示例代码

2022-11-08 18:48| 来源: 网络整理| 查看: 265

Java getWindowManager方法属于android.app.Activity类。

本文搜集整理了关于Java中android.app.Activity.getWindowManager方法 用法示例代码,并附有代码来源和完整的源代码,希望对您的程序开发有帮助。

本文末尾还列举了关于getWindowManager方法的其它相关的方法列表供您参考。

CommonUtil.getCurrentScreenLand(...) public static boolean getCurrentScreenLand(Activity context) { return context.getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_90 || context.getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_270; } } 代码来源:CarGuo/GSYVideoPlayer SimpleHomeAdapter.(...) public SimpleHomeAdapter(Context context, String[] items) { this.mContext = context; this.mItems = items; mDisplayMetrics = new DisplayMetrics(); ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(mDisplayMetrics); } 代码来源:H07000223/FlycoTabLayout CommonUtils.getDisplayWidth(...) public static int getDisplayWidth(Activity activity){ int width=0; if (activity != null && activity.getWindowManager() != null && activity.getWindowManager().getDefaultDisplay() != null) { Point point=new Point(); activity.getWindowManager().getDefaultDisplay().getSize(point); width = point.x; } return width; } 代码来源:zwwill/yanxuan-weex-demo AndroidInput.getRotation() @Override public int getRotation () { int orientation = 0; if (context instanceof Activity) { orientation = ((Activity)context).getWindowManager().getDefaultDisplay().getRotation(); } else { orientation = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); } switch (orientation) { case Surface.ROTATION_0: return 0; case Surface.ROTATION_90: return 90; case Surface.ROTATION_180: return 180; case Surface.ROTATION_270: return 270; default: return 0; } } 代码来源:libgdx/libgdx

AndroidInput.getRotation() @Override public int getRotation () { int orientation = 0; if (context instanceof Activity) { orientation = ((Activity)context).getWindowManager().getDefaultDisplay().getRotation(); } else { orientation = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); } switch (orientation) { case Surface.ROTATION_0: return 0; case Surface.ROTATION_90: return 90; case Surface.ROTATION_180: return 180; case Surface.ROTATION_270: return 270; default: return 0; } } 代码来源:libgdx/libgdx Util.getScreenWidth(...) public static int getScreenWidth(Activity activity) { Display display = activity.getWindowManager().getDefaultDisplay(); DisplayMetrics outMetrics = new DisplayMetrics(); display.getMetrics(outMetrics); return outMetrics.widthPixels; } 代码来源:arimorty/floatingsearchview Utils.getScreenPix(...) /** * 获取手机大小(分辨率) */ public static DisplayMetrics getScreenPix(Activity activity) { DisplayMetrics displaysMetrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(displaysMetrics); return displaysMetrics; } 代码来源:jeasonlzy/ImagePicker Utils.getWindowHeight(...) public static int getWindowHeight(Activity context) { DisplayMetrics metric = new DisplayMetrics(); context.getWindowManager().getDefaultDisplay().getMetrics(metric); return metric.heightPixels; } 代码来源:sunfusheng/MarqueeView

Util.getScreenHeight(...) public static int getScreenHeight(Activity activity) { Display display = activity.getWindowManager().getDefaultDisplay(); DisplayMetrics outMetrics = new DisplayMetrics(); display.getMetrics(outMetrics); return outMetrics.heightPixels; } 代码来源:arimorty/floatingsearchview StrUtils.getdensity(...) public static float getdensity(Activity activity) { DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); float density = dm.density; return density; } 代码来源:jiangqqlmj/FastDev4Android StrUtils.getScreenSize(...) public static int getScreenSize(Activity activity) { int widthPixels = 0; int heightPixels = 0; DisplayMetrics dm = new DisplayMetrics(); if (dm != null) { activity.getWindowManager().getDefaultDisplay().getMetrics(dm); widthPixels = dm.widthPixels; heightPixels = dm.heightPixels; } return widthPixels * heightPixels; } 代码来源:jiangqqlmj/FastDev4Android DensityUtil.getWindowHeight(...) public static int getWindowHeight(Activity activity){ DisplayMetrics metric = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metric); return metric.heightPixels; } } 代码来源:sunfusheng/StickyHeaderListView Utils.getWindowWidth(...) public static int getWindowWidth(Activity context) { DisplayMetrics metric = new DisplayMetrics(); context.getWindowManager().getDefaultDisplay().getMetrics(metric); return metric.widthPixels; } 代码来源:sunfusheng/MarqueeView

DensityUtil.getWindowWidth(...) public static int getWindowWidth(Activity context){ DisplayMetrics metric = new DisplayMetrics(); context.getWindowManager().getDefaultDisplay().getMetrics(metric); return metric.widthPixels; } 代码来源:sunfusheng/StickyHeaderListView SystemBarTintManager$SystemBarConfig.getSmallestWidthDp(...) @SuppressLint("NewApi") private float getSmallestWidthDp(Activity activity) { DisplayMetrics metrics = new DisplayMetrics(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics); } else { // TODO this is not correct, but we don't really care pre-kitkat activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); } float widthDp = metrics.widthPixels / metrics.density; float heightDp = metrics.heightPixels / metrics.density; return Math.min(widthDp, heightDp); } 代码来源:TommyLemon/APIJSON 如何在 Android 中检查软件键盘的可见性? import android.app.Activity; import android.content.Context; import android.graphics.Rect; import android.util.AttributeSet; import android.widget.LinearLayout; /* * LinearLayoutThatDetectsSoftKeyboard - a variant of LinearLayout that can detect when * the soft keyboard is shown and hidden (something Android can't tell you, weirdly). */ public class LinearLayoutThatDetectsSoftKeyboard extends LinearLayout { public LinearLayoutThatDetectsSoftKeyboard(Context context, AttributeSet attrs) { super(context, attrs); } public interface Listener { public void onSoftKeyboardShown(boolean isShowing); } private Listener listener; public void setListener(Listener listener) { this.listener = listener; } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int height = MeasureSpec.getSize(heightMeasureSpec); Activity activity = (Activity)getContext(); Rect rect = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect); int statusBarHeight = rect.top; int screenHeight = activity.getWindowManager().getDefaultDisplay().getHeight(); int diff = (screenHeight - statusBarHeight) - height; if (listener != null) { listener.onSoftKeyboardShown(diff>128); // assume all soft keyboards are at least 128 pixels high } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } 代码来源:stackoverflow.com SystemBarTintManager$SystemBarConfig.getSmallestWidthDp(...) @SuppressLint("NewApi") private float getSmallestWidthDp(Activity activity) { DisplayMetrics metrics = new DisplayMetrics(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics); } else { // TODO this is not correct, but we don't really care pre-kitkat activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); } float widthDp = metrics.widthPixels / metrics.density; float heightDp = metrics.heightPixels / metrics.density; return Math.min(widthDp, heightDp); } 代码来源:jeasonlzy/ImagePicker RxMapScaleView.getPPIOfDevice() private double getPPIOfDevice() { Point point = new Point(); Activity activity = (Activity) context; activity.getWindowManager().getDefaultDisplay().getRealSize(point);//获取屏幕的真实分辨率 DisplayMetrics dm = getResources().getDisplayMetrics(); double x = Math.pow(point.x / dm.xdpi, 2);// double y = Math.pow(point.y / dm.ydpi, 2); double screenInches = Math.sqrt(x + y); Double ppi = Math.sqrt(Math.pow(point.x, 2) + Math.pow(point.y, 2)) / screenInches; return ppi; } } 代码来源:vondear/RxTool DialogPlusBuilder.getDefaultContentHeight() public int getDefaultContentHeight() { Activity activity = (Activity) context; Display display = activity.getWindowManager().getDefaultDisplay(); int displayHeight = display.getHeight() - Utils.getStatusBarHeight(activity); if (defaultContentHeight == 0) { defaultContentHeight = (displayHeight * 2) / 5; } return defaultContentHeight; } 代码来源:orhanobut/dialogplus ShadowViewTest.removeAllViews_shouldCallOnAttachedToAndDetachedFromWindow() @Test public void removeAllViews_shouldCallOnAttachedToAndDetachedFromWindow() throws Exception { MyView parent = new MyView("parent", transcript); Activity activity = Robolectric.buildActivity(ContentViewActivity.class).create().get(); activity.getWindowManager().addView(parent, new WindowManager.LayoutParams(100, 100)); parent.addView(new MyView("child", transcript)); parent.addView(new MyView("another child", transcript)); ShadowLooper.runUiThreadTasks(); transcript.clear(); parent.removeAllViews(); ShadowLooper.runUiThreadTasks(); assertThat(transcript).containsExactly("another child detached", "child detached"); } 代码来源:robolectric/robolectric

相关方法: android.app.Activity.onCreate android.app.Activity.getWindow android.app.Activity.finish android.app.Activity.onDestroy android.app.Activity.onResume android.app.Activity.findViewById android.app.Activity.startActivity android.app.Activity.getResources android.app.Activity.startActivityForResult android.app.Activity.onPause android.app.Activity.getSystemService android.app.Activity.runOnUiThread android.app.Activity.getSystemService android.app.Activity.runOnUiThread android.app.Activity.isFinishing android.app.Activity.getString android.app.Activity.onStop android.app.Activity.getApplicationContext android.app.Activity.onStart android.app.Activity.onOptionsItemSelected android.app.Activity.getPackageName


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3