0

how to show a web page with webview in BottonSheetDialog ! like this

click here for see example image

farid
  • 300
  • 1
  • 8
  • Have you tried anything before asking? – B001ᛦ Jul 13 '20 at 18:54
  • just google it , i was able to found the solution by searching how to show website in Bottonsheetdialog , if you have a problem with your code paste it here so we can help you , check this [bottomSheetDialogFragment full screen](https://stackoverflow.com/questions/58065771/bottomsheetdialogfragment-full-screen) – anehme Jul 13 '20 at 19:05
  • yeah just error !!! i check that but no help me – farid Jul 13 '20 at 19:09
  • It's hard to help with an error without seeing the original error message. Please edit your post to include the exact wording of any error messages, including the full [stack trace](/a/23353174) of any exceptions, if applicable, as well as which line of code the stack trace points to. Please see [ask] and [How to create a Minimal, Reproducible Example](/help/minimal-reproducible-example) – Ryan M Jul 13 '20 at 23:59

1 Answers1

2

To do you have to create a class that extends BottomSheetDialogFragment, you have to create a layout that contains a webview, then call oncreateview() method where you inflate layout and set up the webview with its reference from the layout, then in your activity show the bottomsheetdialog

*First create a layout:

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/webview"/>

</androidx.constraintlayout.widget.ConstraintLayout>
  • Secondly create a class that extends BottomSheetDialogFragment
//Extend Your class with BottomSheetDialogFragment
public class WebViewBottomSheet extends BottomSheetDialogFragment{

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        
        //Inflate Your layout which contains the webView
        View view = inflater.inflate(R.layout.weblayout,container,false);

        WebView webView = view.findViewById(R.id.webview);
        webView.loadUrl("Put your URL here");
        return view;
    }
}

  • And finally just show your BottomSheet in your activity
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        
        //Here you show your BottomSheetDialog
        WebViewBottomSheet webViewBottomSheet = new WebViewBottomSheet();
        webViewBottomSheet.show(getSupportFragmentManager(),"Show Bottom Sheet");
    }
}

PS: Don't forget to add the design library to your project

Dharman
  • 30,962
  • 25
  • 85
  • 135
Taki
  • 3,290
  • 1
  • 16
  • 41