欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

android获取屏幕像素思路及代码

程序员文章站 2023-11-28 22:44:40
复制代码 代码如下: private void alertscreendialog() { disp...
复制代码 代码如下:

<span style="font-size: 18px">private void alertscreendialog() {
displaymetrics dm = new displaymetrics();
getwindowmanager().getdefaultdisplay().getmetrics(dm);
string optstr = "手机屏幕分辨率为: "+dm.widthpixels+" x "+dm.heightpixels;
builder builder = new builder(this);
builder.setmessage(optstr);
builder.seticon(r.drawable.firefox);
builder.settitle("获取屏幕像素");
//点击确定按钮
builder.setpositivebutton("确定", new dialoginterface.onclicklistener(){
@override
public void onclick(dialoginterface dialog, int which) {
toast.maketext(getscreenactivity.this, "获取到像素", toast.length_long).show();
}
});
builder.setnegativebutton("返回", new dialoginterface.onclicklistener() {
@override
public void onclick(dialoginterface dialog, int which) {
toast.maketext(getscreenactivity.this, "返回", toast.length_long).show();
}
});
builder.create().show();
}</span>