java - 如何在Bottonsheetdialog android studio中显示网站
解决方案
要做到这一点,您必须创建一个扩展类BottomSheetDialogFragment
,您必须创建一个包含 a 的布局webview
,然后调用oncreateview()
您膨胀布局的方法并webview
使用布局中的引用设置 ,然后在您的活动中显示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 的类
//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;
}
}
- 最后,只需在您的活动中显示您的 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:不要忘记将设计库添加到您的项目中
推荐阅读
- java - 泛型的番石榴缓存错误
- cmake - 如何用cmake进行条件变量赋值?
- python - 连接后熊猫排序和重新索引
- eclipse-rcptt - 在 rcptt 中右键单击无法重播
- c# - 使用 RouteDataRequestCultureProvider 处理 ASP.NET Core 错误
- javascript - jQuery | 从多个具有特定文本的跨度中选择类
- java - 为什么使用 Mockito 进行 JUnit 测试而不定义“何时”方法?
- c# - C#应用程序和USB设备之间的USB速度测试
- angular - 如何在 Angular 5 中使用启用下拉菜单的自动完成功能?
- javascript - 如何以可读格式获取 JS 模板文字中 Map 对象的内容?