I'm working application. when button click happens, it displays popup window with videoview. It is showing in android 29 api, but not in android 24 api. the following is the code of showvideopopup function for it.
private void showVideoPopup()
{
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View customView = layoutInflater.inflate(R.layout.dispensing_intro,null);
int uiOptions =View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
customView.setSystemUiVisibility(uiOptions);
// closePopupBtn = (Button) customView.findViewById(R.id.closeView);
//instantiate popup window
dispense_intro_popup = new PopupWindow(customView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
//display the popup window
dispense_intro_popup.showAtLocation(dispense_intro_view, Gravity.CENTER, 0, 0);
VideoView video = (VideoView) customView.findViewById(R.id.dispense_intro);
Uri videoUri = Uri.parse("android.resource://" + getPackageName() + "/raw/"+ R.raw.dispense_intro);
video.setVideoURI(videoUri);
video.start();
video.setOnCompletionListener(this);
}
The Following is the popup.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="#b3000000"
android:layout_height="700dp"
android:id="@+id/dispense_intro_holder"
android:layout_gravity="center"
android:gravity="center">
<VideoView
android:id="@+id/dispense_intro"
android:layout_gravity="center"
android:layout_width="640dp"
android:layout_height="360dp" />
</LinearLayout>
Use DialogFragment()
instead of PopupWindow
.
Then add the following code to fragment onCreateView
PopupFragment.java
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.popup, container, false);
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.FullscreenTheme);
VideoView video = (VideoView) rootView.findViewById(R.id.dispense_intro);
Uri videoUri = Uri.parse("android.resource://" + getPackageName() + "/raw/"+ R.raw.dispense_intro);
video.setVideoURI(videoUri);
video.start();
video.setOnCompletionListener(this);
return rootView;
}
And to make dialog fragment to full screen use the following code for onDialogCreated
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
// Hide the nav bar and status bar
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
return dialog;
}