Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;

import android.graphics.Bitmap;

import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

import android.widget.ImageButton;

public class Main {
    public static void changeImageButton(Context context, ImageButton button, int resId, int width, int height) {
        Drawable icon;
        icon = context.getResources().getDrawable(resId);
        icon.setBounds(0, 0, width, height);
        Bitmap iconBitmap = ((BitmapDrawable) icon).getBitmap();
        Bitmap bitmapResized = Bitmap.createScaledBitmap(iconBitmap, width, height, false);
        button.setImageBitmap(bitmapResized);

    }
}