当前位置: 编程技术>移动开发
android获取屏幕像素思路及代码
来源: 互联网 发布时间:2014-10-14
本文导语: 代码如下: 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); bui...
代码如下:
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();
}