private void newGame() { game = new Game(gameSettings.getBoardSize(), gameSettings.getNumColors()); lastColor = game.getColor(0, 0); // Add color buttons LinearLayout buttonLayout = (LinearLayout) findViewById(R.id.buttonLayout); buttonLayout.removeAllViews(); Resources resources = getResources(); for (int i = 0; i < gameSettings.getNumColors(); i++) { final int localI = i; ImageView newButton = new ImageView(this); newButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { v.startAnimation(AnimationUtils.loadAnimation(GameActivity.this, R.anim.button_anim)); if (localI != lastColor) { doColor(localI); } } }); newButton.setLayoutParams( new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f)); Drawable buttonDrawable = ContextCompat.getDrawable(this, R.drawable.button); buttonDrawable.setColorFilter(paints[i].getColor(), PorterDuff.Mode.SRC_ATOP); newButton.setImageDrawable(buttonDrawable); newButton.setPadding(5, 5, 5, 5); buttonLayout.addView(newButton); } stepsTextView.setText(game.getSteps() + " / " + game.getMaxSteps()); floodView.setBoardSize(gameSettings.getBoardSize()); floodView.drawGame(game); }