Android Dialog(非自定义)问题

标签 android android-alertdialog

当没有可用的互联网连接时,我试图显示一个简单的警报来处理我的 Activity ,但是,由于某种我不知道的原因,当我设置警报图标时,该框变得杂乱无章,太大了。下面是我的代码:

@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;
}

这段代码的结果如下图所示。

device screenshot

我做错了什么?我错过了什么吗?这段代码是直接从 API 演示源代码中复制的,它在我的设备上完美运行。

非常感谢

最佳答案

最好的方法是更改​​图标大小。如果您想以编程方式执行此操作,请查看此内容..

    // 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);

关于Android Dialog(非自定义)问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5405041/

相关文章:

android - 在两个警报对话框之间传递信息

Android NavigationView 设置默认 fragment

android - 向智能手机日历添加约会和提醒的移动应用程序

javascript - 如何使用 android studio 创建一个带有存储在网络服务器上的数组的 android 应用程序?

java - 在 AlertDialog 中引用多个复选框

java - 以编程方式 Linearlayout 使用属性设置背景颜色

java - 在 Alert Dialog Builder 中编辑文本

Android-如何等待 AlertDialog 检查?

android - "ifconfig"在 Genymotion 上没有显示任何内容

java - Android videoview 不播放 rtsp