Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android对话框(非自定义)问题_Android_Android Alertdialog - Fatal编程技术网

Android对话框(非自定义)问题

Android对话框(非自定义)问题,android,android-alertdialog,Android,Android Alertdialog,当没有可用的internet连接时,我试图在我的活动中显示一个简单的警报,但是,由于某些原因,我不知道,当我设置警报图标时,框变得凌乱,太大。下面是我的代码: @Override protected Dialog onCreateDialog(int id) { switch (id) { case 1: return new AlertDialog.Builder(SplashScreen.this) .setTitle("Aviso")

当没有可用的internet连接时,我试图在我的活动中显示一个简单的警报,但是,由于某些原因,我不知道,当我设置警报图标时,框变得凌乱,太大。下面是我的代码:

@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演示源代码,它在我的设备上运行得非常好

非常感谢
T

可能是您正在使用的图标,但其尺寸较大。。。。
将图像缩放为位图至小尺寸,并使用位图可绘制。。!!您使用的图标可能不是id,而是大尺寸的。。。。
将图像缩放为位图至小尺寸,并使用位图可绘制。。!!最好的方法是更改图标大小,而不是id。如果您想以编程方式执行此操作,请检查此

    // 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);
此位图可按如下方式使用


建造商:setIcon(bmd)

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

    // 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);
此位图可按如下方式使用

建造商:setIcon(bmd)

没有
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);
没有
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);

这很奇怪,因为对话框代码和图像是从API演示源代码复制的,这对我在模拟器和我的设备上都很好。然后你说使用的代码和图像也是从API演示源代码复制的。你也说它工作得很好。但是你说“当我为警报设置图标时,框会变得混乱”意味着图像是prblm…所以使用较小的图像并检查一次…我从api演示更改为ldpi图像,它开始工作。我会继续尝试,因为我的屏幕是ldpi,所以图像质量下降。谢谢如果您使用QVGA place image ldpi,…类似地,HVGA使用mdpi,WVGA使用hdpi..然后您可以控制图像质量..这很奇怪,因为对话框代码和从API演示源代码复制的图像,这对我在模拟器和我的设备上都很好。然后你说使用的代码和图像也是来自API演示源。你也说它工作得很好。但是你说“当我设置警报图标时,框变得很乱”意味着图像是prblm…所以使用较小的图像并检查一次…我从api演示更改为ldpi图像,它开始工作。我会继续尝试,因为我的屏幕是ldpi,所以图像质量下降。感谢如果您使用QVGA放置图像ldpi,…类似地,HVGA使用mdpi,WVGA使用hdpi..那么您可以控制图像质量。。