如何在 Bottomsheetdialog android studio 中显示网站
how to show website in Bottonsheetdialog android studio
如何在 BottonSheetDialog 中使用 webview 显示网页!
像这样
click here for see example image
您必须创建一个扩展 BottomSheetDialogFragment
的 class,您必须创建一个包含 webview
的布局,然后调用 oncreateview()
方法膨胀布局并使用布局中的参考设置 webview
,然后在您的 activity 中显示 bottomsheetdialog
*首先创建布局:
<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>
- 其次创建一个扩展 BottomSheetDialogFragment
的 class
//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;
}
}
- 最后只需在 activity
中显示 BottomSheet
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: 不要忘记将设计库添加到您的项目中
如何在 BottonSheetDialog 中使用 webview 显示网页! 像这样
click here for see example image
您必须创建一个扩展 BottomSheetDialogFragment
的 class,您必须创建一个包含 webview
的布局,然后调用 oncreateview()
方法膨胀布局并使用布局中的参考设置 webview
,然后在您的 activity 中显示 bottomsheetdialog
*首先创建布局:
<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>
- 其次创建一个扩展 BottomSheetDialogFragment 的 class
//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;
}
}
- 最后只需在 activity 中显示 BottomSheet
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: 不要忘记将设计库添加到您的项目中