There is a button created and displayed in Canvas, but when pressed it does not respond and a pop-up message is not triggered. What can I change to make the listener work? There is another feature: the button is displayed, but when pressed, it does not visually change (as if it is behind glass and a finger does not reach it). Maybe you need some sort of order to change the canvas-button / button-canvas?
public class ButtonInCanvas extends AppCompatActivity implements View.OnClickListener { Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); button = new Button(ButtonInCanvas.this); button.setOnClickListener(this); button.setText("OK!"); setContentView(new BtInCanvas(ButtonInCanvas.this)); } public class BtInCanvas extends View { public BtInCanvas(Context context) { super(context); } public void onDraw(Canvas canvas){ button.layout(50,50,300,300); button.draw(canvas); } } @Override public void onClick(View v) { Toast.makeText(this,"OK!",Toast.LENGTH_LONG).show(); } }