标签: bottomsheetdialogfragment

如何在 BottomSheetDialogFragment 中正确使用 Jetpack Compose?

例如,我在应用程序中有 MyBottomSheetDialogFragment 和 Compose LazyColumn 代码:

class MyBottomSheetDialogFragment : BottomSheetDialogFragment() {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        return ComposeView(requireContext()).apply {
            setContent {
                Column(horizontalAlignment = Alignment.CenterHorizontally) {
                    Text("Header", color = Color.Black)
                    LazyColumn(
                        Modifier
                            .weight(1f)
                            .fillMaxWidth()) {
                        items(100) {
                            Text("Item $it", Modifier.fillMaxWidth(), Color.Black)
                        }
                    }
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

并使用以下代码显示它:

MyBottomSheetDialogFragment().show(activity.supportFragmentManager, null)
Run Code Online (Sandbox Code Playgroud)

这就是我们所拥有的:

MyBottomSheetDialogFragment 屏幕图像.jpg

现在,如果向下滚动 LazyColumn 列表,则一切都会正常工作,但如果向上滚动 LazyColumn 列表,则底部工作表对话框将滚动,而不是 LazyColumn 列表。

如何在 BottomSheetDialogFragment 中正确实现 LazyColumn?

当我们使用 XML RecyclerView 列表时,要解决此问题,我们必须使用 NestedScrollView 包装 RecyclerView 列表,如此处所述 …

android-jetpack-compose android-bottomsheetdialog bottomsheetdialogfragment android-jetpack-compose-list lazycolumn

10
推荐指数
1
解决办法
4450
查看次数

有时 BottomSheetDialogFragment 在屏幕中央打开,如警报对话框

我有 BottomSheetDialogFragment ,它需要在展开状态下打开,并且应该在向下滑动时跳过折叠状态。

问题是,我有时会遇到意想不到的行为

意外行为

为什么我有时会看到这样的观点?

下面是我的代码,

@Override
    public int getTheme() {
        if (Build.VERSION.SDK_INT > 21) {
            return R.style.BottomSheetDialogTheme;
        } else {
            return super.getTheme();
        }
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);

        dialog.setOnShowListener((DialogInterface.OnShowListener) dialog1 -> {
            BottomSheetDialog d = (BottomSheetDialog) dialog1;
            FrameLayout bottomSheet = (FrameLayout) d.findViewById(com.google.android.material.R.id.design_bottom_sheet);
            if (bottomSheet != null) {
                BottomSheetBehavior.from(bottomSheet).setState(BottomSheetBehavior.STATE_EXPANDED);
                BottomSheetBehavior.from(bottomSheet).setSkipCollapsed(true);
                BottomSheetBehavior.from(bottomSheet).setFitToContents(true);
                BottomSheetBehavior.from(bottomSheet).setPeekHeight(1000);
            }
        });

        return dialog;
    }
Run Code Online (Sandbox Code Playgroud)

相同的风格/主题是

     <style name="BottomSheetDialogTheme" parent="BaseBottomSheetDialog">
            <item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/transparent
            </item>
        </style>
        <!-- set the rounded drawable as …
Run Code Online (Sandbox Code Playgroud)

android android-bottomsheetdialog bottomsheetdialogfragment

6
推荐指数
1
解决办法
1614
查看次数

如何将底部对话框片段中的稀松布更改为不可见?

我已经使用bottomsheetdialogfragment 实现了bottomsheet。但默认它具有调光效果(稀松布)。如何删除或将调光效果(稀松布)更改为不可见,以便我可以清楚地看到其他 UI 元素。

这是我使用的布局。

fragment_bottom_sheet_queue.xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/res_bottom_sheet_shape"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="6dp">

        <ImageView
            android:id="@+id/close"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginStart="10dp"
            android:layout_marginTop="8dp"
            android:background="?selectableItemBackgroundBorderless"
            android:contentDescription="@string/image_description"
            android:padding="10dp"
            android:src="@drawable/ic_close" />

        <TextView
            android:id="@+id/txt_queue"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_gravity="center"
            android:layout_marginStart="8dp"
            android:layout_marginEnd="8dp"
            android:fontFamily="@font/quicksand_medium"
            android:gravity="center"
            android:text="@string/queue"
            android:textColor="@color/dark_white"
            android:textSize="18sp" />

        <ImageView
            android:id="@+id/option"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_gravity="center_vertical"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="8dp"
            android:background="?selectableItemBackgroundBorderless"
            android:contentDescription="@string/image_description"
            android:padding="10dp"
            android:src="@drawable/ic_menu" />
        <ImageView
            android:id="@+id/tickoption"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_gravity="center_vertical"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="8dp"
            android:visibility="gone"
            android:background="?selectableItemBackgroundBorderless"
            android:contentDescription="@string/image_description"
            android:padding="10dp"
            android:src="@drawable/ic_done_grey_24dp" />
    </RelativeLayout>

    <View
        android:id="@+id/view"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginTop="6dp"
        android:background="@color/light_grey" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-bottomsheetdialog bottomsheetdialogfragment

5
推荐指数
2
解决办法
1536
查看次数

Dagger-Hilt @AndroidEntryPoint 不适用于 BottomSheetDialogFragment()

我在 BottomSheetDialogFragmet() 中使用 ViewModel,所以我必须用 @AndroidEntryPoint 标记我的 BottomSheet。

\n
@AndroidEntryPoint\nclass SearchAddressDialog : BottomSheetDialogFragment() {\n\n    private val viewModel: MyAddressesViewModel by viewModels()\n    \n    ......\n}\n
Run Code Online (Sandbox Code Playgroud)\n

但是当我尝试构建我的项目时,它给了我这个错误:

\n
Execution failed for task \':app:kaptDebugKotlin\'.\n> A failure occurred while executing \norg.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction\n> java.lang.reflect.InvocationTargetException (no error message)\n\n* Try:\nRun with --stacktrace option to get the stack trace. Run with --info or --debug option \nto get more log output. Run with --scan to get full insights.\n
Run Code Online (Sandbox Code Playgroud)\n

这是我使用 --stacktrace 运行的输出

\n

https://gist.github.com/javlonrahimov/95de968645cace1dfb6e425381f8014b

\n

如果我删除 BottomSheetFragmen() 上方的 @AndroidEntryPoint,它将构建并安装应用程序。但是当我尝试打开 BottomSheet 时,当我将存储库注入 …

android gradle dagger-hilt bottomsheetdialogfragment

5
推荐指数
1
解决办法
4966
查看次数

如何在Android ButtomSheetDialogFragment 中设置左右边距?

我试图在ButtonSheetDialogFragment布局中设置 Margin但它不起作用。我试图从布局和编程中设置边距,但结果相同

这是我的 XML 文件 layout_bts_item.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="10dp"
    android:background="#00000000">
   <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </LinearLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的java代码

        public class ButtomSheetFragment extends BottomSheetDialogFragment {
    
        private BottomSheetBehavior.BottomSheetCallback mBottomSheetBehaviorCallback = new BottomSheetBehavior.BottomSheetCallback() {
          @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState)      {
                if (newState == BottomSheetBehavior.STATE_HIDDEN) {
                    dismiss();
                }
    
            }
    
            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {
            }
        };
    
        @Override
        public void setupDialog(Dialog dialog, int style) {
            super.setupDialog(dialog, style);
    
            View contentView = View.inflate(getContext(),         R.layout.layout_bts_item, null); …
Run Code Online (Sandbox Code Playgroud)

layout android fragment bottomsheetdialogfragment

4
推荐指数
1
解决办法
2982
查看次数

为什么我的 BottomSheetDialogFragment 忽略我的应用程序主题?

我刚刚开始BottomSheetDialogFragment在我的应用程序中使用 a,但它似乎忽略了我的应用程序主题。我的应用程序使用深色主题,并且BottomSheetDialogFragment 显示为白色背景,并且不使用我的应用程序的强调色。这是唯一具有这种行为的 Android 组件。为什么会这样以及如何解决这个问题?

public class CustomBottomDialogFragment extends BottomSheetDialogFragment {

    public static CustomBottomDialogFragmentnewInstance(long id) {
        final CustomBottomDialogFragmentdialog = new CustomBottomDialogFragment();
        Bundle args = new Bundle();
        args.putLong(Keys.ARG1, id);
        dialog.setArguments(args);
        return dialog;
    }

  @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        final long id = getArguments().getLong(Keys.ARG1);
        final boolean isLiveStream = PodcastHelper.isLiveStream(podcastId);
        final View view = inflater.inflate(R.layout.custom_bottom_sheet_layout, container, false);

...

        return view;
    }
Run Code Online (Sandbox Code Playgroud)

android android-theme bottom-sheet bottomsheetdialogfragment

4
推荐指数
1
解决办法
2443
查看次数

如何让BottomSheetDialog全屏显示?

我有这个简单的 BottomSheetDialog,我想将其全屏显示:

class RegistrationDialog : BottomSheetDialogFragment() {


    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        var view = inflater.inflate(R.layout.dialog_registration, container, false)
        return view

    }
}
Run Code Online (Sandbox Code Playgroud)

android kotlin bottom-sheet android-bottomsheetdialog bottomsheetdialogfragment

1
推荐指数
1
解决办法
5371
查看次数