我试图在没有互联网连接的情况下显示一个处理我的活动的简单警报,但是,出于某些原因我不知道,当我设置警报的图标时,框变得凌乱,太大了。以下是我的代码:
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case 1:
return new AlertDialog.Builder(SplashScreen.this)
.setTitle("Aviso")
.setIcon(R.drawable.alert_dialog_icon)
.setMessage("Acesso à internet não disponível. Clique OK para sair.")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
SplashScreen.this.finish();
}
})
.create();
}
return null;
}
此代码的结果显示在下图中。
我做错了什么?我错过了什么吗?此代码直接从API演示源代码中复制,该代码在我的设备中完美运行。
非常感谢 Ť
答案 0 :(得分:2)
最好的方法是更改图标大小。如果你想以编程方式进行检查,请查看..
// load the origial BitMap (500 x 500 px)
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
R.drawable.android);
int width = bitmapOrg.width();
int height = bitmapOrg.height();
int newWidth = 200;
int newHeight = 200;
// calculate the scale - in this case = 0.4f
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// createa matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
// rotate the Bitmap
matrix.postRotate(45);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,
width, height, matrix, true);
// make a Drawable from Bitmap to allow to set the BitMap
// to the ImageView, ImageButton or what ever
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
此位图可以按如下方式使用
builder.setIcon(BMD);
答案 1 :(得分:1)
可能是您正在使用的图标 .... 将图像缩放到位图到最小尺寸并使用 BitmapDrawable .. !!而不是id
答案 2 :(得分:1)
没有width()
和Height()
函数,下面是更正后的代码:
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(), R.drawable.cyj);
int width = bitmapOrg.**getWidth**();
int height = bitmapOrg.**getHeight()**;
int newWidth = 45;
int newHeight = 45;
// calculate the scale - in this case = 0.4f
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// create matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
// rotate the Bitmap
matrix.postRotate(0);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,
width, height, matrix, true);
// make a Drawable from Bitmap to allow to set the BitMap
// to the ImageView, ImageButton or what ever
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);