Button button = findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!button.isShown()) { Snackbar.make(v, "The button is not currently visible", Snackbar.LENGTH_SHORT).show(); } } });
VideoView videoView = findViewById(R.id.video_view); if (videoView.isShown()) { videoView.pause(); }This code checks if the VideoView is currently visible using the isShown method and pauses the video if the VideoView is visible. If the VideoView is not visible, the code does not do anything. Package Library: android.widget.VideoView