how to put image in button android studio code example

Example 1: android studio change image on button click

ImageButton btn = (ImageButton)findViewById(R.id.imageButton1);       
 btn.setImageResource(R.drawable.actions_record);

Example 2: how images button work in android studio

/*Add in Oncreate() funtion after setContentView()*/
ImageButton simpleImageButton = (ImageButton) findViewById(R.id.simpleImageButton);
simpleImageButton.setBackgroundColor(Color.BLACK); //set black background color for image button

Tags:

Java Example