如何获得应用类屏幕显示指标如何获得、屏幕、指标

由网友(把愚勇熬成温柔)分享简介:如果我把这个部分它完美活动课,但是,当我把它放在我的应用程序类中的方法 getWindowManager()无法找到。有一些办法让窗口管理器中的应用程序类?我的应用程序类的定义是这样的:公共类对myApp扩展应用{和在创建方法我有这样的:DisplayMetrics DM =新DisplayMetrics();。ge...

如果我把这个部分它完美活动课,但是,当我把它放在我的应用程序类中的方法 getWindowManager()无法找到。有一些办法让窗口管理器中的应用程序类?

我的应用程序类的定义是这样的:

 公共类对myApp扩展应用{
 

和在创建方法我有这样的:

  DisplayMetrics DM =新DisplayMetrics();
。getWindowManager()getDefaultDisplay()getMetrics(DM)。
INT宽度= dm.widthPixels;
 
旅游大数据平台,实现旅游全域化管理

解决方案

下面,Context.getResource()

  DisplayMetrics DM = getResources()getDisplayMetrics()。
INT densityDpi = dm.densityDpi;  

If I put this in some activity class it works perfectly but, when I put it in my App class the method getWindowManager() can not be found. Is there some way to get the WindowManager in app class?

My app class is defined like this:

public class myApp extends Application {

and in on create method I have this:

DisplayMetrics dm = new DisplayMetrics(); 
getWindowManager().getDefaultDisplay().getMetrics(dm); 
int width = dm.widthPixels;

解决方案

Here, Context.getResource()

DisplayMetrics dm = getResources().getDisplayMetrics(); 
int densityDpi = dm.densityDpi;

阅读全文

相关推荐

最新文章