I am developing an Android app that can play videos. While using VideoView to play videos, I encountered a bug where part of the navigation using DrawerLayout is not visible but clickable after the video is paused. The navigation works fine until the video is paused. Is there a solution?
Below is the code snippet I’m currently working on.
Activity part
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_play_list);
navWrap = findViewById(R.id.nav_wrap);
initNavigation();
initVideoView();
initEvent();
playButton = findViewById(R.id.play_btn);
}
public void initNavigation(){
drawerLayout = findViewById(R.id.drawer_layout);
navigationView = findViewById(R.id.nav_view);
if (!drawerLayout.isDrawerOpen(Gravity.LEFT)) {
drawerLayout.openDrawer(Gravity.LEFT) ;
}
}
public void initVideoView(){
videoView = findViewById(R.id.video_view);
videoView.setVideoPath("url");
videoView.setOnPreparedListener(mp -> {
mp.setLooping(true);
mp.setVolume(0, 0);
mp.start();
});
}
public void initEvent(){
playButtonWrap = findViewById(R.id.play_btn_layout);
playButtonWrap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (videoView.isPlaying()) {
stopVideo();
} else {
startVideo();
}
}
});
}
public void startVideo(){
//video start
videoView.start();
//btn image change
changeBtn(true);
}
public void stopVideo(){
//video stop
videoView.pause();
//btn image change
changeBtn(false);
}
private void changeBtn(boolean isPlaying){
playButton.setVisibility(View.VISIBLE);
navWrap.setVisibility(View.VISIBLE);
playButton.setImageDrawable(isPlaying ? getResources().getDrawable(R.drawable.start) : getResources().getDrawable(R.drawable.pause));
fadeOutAndHideImage(playButton);
}
layout part
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".UI.PlayListActivity"
android:background="@color/background_grey"
>
<VideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/play_btn_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:clickable="true"
>
<ImageView
android:id="@+id/play_btn"
android:layout_width="250px"
android:layout_height="250px"
android:background="@drawable/play_btn_background"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:src="@drawable/start"
android:scaleType="center"
android:scaleY=".8"
android:scaleX=".8"
android:visibility="invisible"
android:clickable="true"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
android:background="@color/thumb_background_black"
android:paddingTop="@dimen/thumbnail_wrap_padding"
android:paddingBottom="@dimen/thumbnail_wrap_padding"
>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/thumbnail_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginStart="120px"
android:layout_marginEnd="120px"
/>
<ImageButton
android:id="@+id/playlist_prev_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/zxing_transparent"
android:src="@drawable/prev"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/thumbnail_recycler_view"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/playlist_next_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="@+id/thumbnail_recycler_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:src="@drawable/next"
android:background="@color/zxing_transparent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<include layout="@layout/nav_view"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.drawerlayout.widget.DrawerLayout>
picture when normal
enter image description here
picture when bug
enter image description here
tv uses android api 25
how can i fix it? do you have any idea?
김종혁 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.