gpt4 book ai didi

android - 如何在android中获取屏幕类型?

转载 作者:行者123 更新时间:2023-11-30 03:44:51 27 4
gpt4 key购买 nike

我在上面使用了它并运行了不同的模拟器,比如大、中、小。但是我的 toast 正常屏幕..如何解决它

    if ((this.getResources().getConfiguration().screenLayout & 
Configuration.SCREENLAYOUT_SIZE_MASK) ==
Configuration.SCREENLAYOUT_SIZE_LARGE) {
Toast.makeText(this, "Large screen",Toast.LENGTH_LONG).show();
}
else if(((this.getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK) ==
Configuration.SCREENLAYOUT_SIZE_NORMAL)) {
Toast.makeText(this, "Normal screen",Toast.LENGTH_LONG).show();
}
else if(((this.getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK) ==
Configuration.SCREENLAYOUT_SIZE_SMALL)) {
Toast.makeText(this, "small screen",Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(this, "Xlarge screen",Toast.LENGTH_LONG).show();
}

最佳答案

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;

阅读下面的代码:- http://developer.android.com/guide/practices/screens_support.html

现在放置 if 条件。

关于android - 如何在android中获取屏幕类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15156455/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com