赞
踩
implementation 'com.android.support:design:29.1.0'
package com.zhangyu.bottomsheetdialog; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.google.android.material.bottomsheet.BottomSheetDialogFragment; public class BottomDialogFragment1 extends BottomSheetDialogFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_bottom_dialog, container, false); initView(view); return view; } private void initView(View view) { } }
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void onClick(View view) { switch (view.getId()){ case R.id.bt_test_1: new BottomDialogFragment1().show(getSupportFragmentManager(),"BottomDialogFragment1"); break; } } }
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FF402416" />
<corners
android:topLeftRadius="16dp"
android:topRightRadius="16dp" />
</shape>
<style name="BottomDialog" parent="@style/Base.V7.Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<!--动画设置-->
<item name="android:windowAnimationStyle">@style/Animation.Design.BottomSheetDialog</item>
</style>
public class BottomDialogFragment2 extends BottomSheetDialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { setStyle(STYLE_NO_TITLE, R.style.BottomDialog); return super.onCreateDialog(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_bottom_dialog, container, false); initView(view); return view; } private void initView(View view) { } }
public class BottomDialogFragment3 extends BottomSheetDialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { setStyle(STYLE_NO_TITLE, R.style.BottomDialog); return super.onCreateDialog(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_bottom_dialog, container, false); view.post(new Runnable() { @Override public void run() { //R.id.design_bottom_sheet基本是固定的,不用担心后面API的更改 BottomSheetBehavior behavior=BottomSheetBehavior.from(getDialog().findViewById(R.id.design_bottom_sheet)); behavior.setHideable(false);//此处设置表示禁止BottomSheetBehavior的执行 } }); initView(view); return view; } private void initView(View view) { } }
public void show(@NonNull FragmentManager manager, @Nullable String tag, String userName, String industry) {
super.show(manager, tag);
this.userName = userName;
this.industry = industry;
}
binding.root.post {
//如果是小屏手机
if (ScreenUtils.getAppScreenHeight() <= 1920) {
val behavior = BottomSheetBehavior.from(requireDialog().findViewById(R.id.design_bottom_sheet))
behavior.peekHeight = binding.airPanelMainLayout.measuredHeight
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。