android获取屏幕像素思路及代码
程序员文章站
2024-02-10 20:44:22
复制代码 代码如下: 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>
下一篇: C#时间操作类分享