标签: bottom-sheet

为什么BottomSheetDialog 将状态栏变成黑色?

我在onCreate()我的活动方法中实现了一个底部工作表,如下所示:

bottomSheet = new BottomSheetDialog(this);
bottomSheet.setContentView(getLayoutInflater().inflate(R.layout.bottom_sheet, null));
bottomSheet.show();
Run Code Online (Sandbox Code Playgroud)

我的 Activity 扩展AppCompatActivity并包含一个TabLayoutViewPager.. 几乎是使用材料设计的标准 UI。

我遇到的问题是,当show()被调用时,状态栏会立即变黑,为底部工作表的平滑动画添加跳跃感,更不用说改变应用程序的配色方案了。

我希望状态栏保持与我的主题相关的默认颜色,并随着底部工作表的展开而平滑变暗。

我已经做了很多搜索,但还没有找到具体的解决方案。

任何想法可能导致这种情况以及我可以采取哪些步骤来解决它?

黑色状态栏(为简单起见删除了 UI 内容) 黑色状态栏(为简单起见删除了 UI 内容)

java android bottom-sheet

4
推荐指数
2
解决办法
4886
查看次数

如何在布局的底部视图中绑定一个BottomSheet

通过 ConstraintLayout,我使用 BottomSheet 来显示地图详细信息的内容。我的想法与 GoogleMaps 中使用的相同,但顶部没有图像轮播。

在此处输入图片说明

我需要找到一些属性将BottomSheet绑定在底部,仅使用其布局的大小,而不是整个窗口,如下所示:

在此处输入图片说明

这是父视图中我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:mapbox="http://schemas.android.com/apk/res-auto"
    android:id="@+id/coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.mapbox.mapboxsdk.maps.MapView
        android:id="@+id/mapview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        mapbox:center_latitude="0"
        mapbox:center_longitude="0"
        mapbox:style_url="@string/style_mapbox_streets"
        mapbox:zoom="12" />

    <!--
    <ImageView
        android:id="@+id/bottom_sheet_backdrop"
        android:layout_width="match_parent"
        android:layout_height="@dimen/anchor_point"
        android:fitsSystemWindows="true"
        app:layout_behavior="@string/BackDropBottomSheetBehavior" />
    -->

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:orientation="vertical"
        app:anchorPoint="@dimen/anchor_point"
        app:behavior_hideable="true"
        app:behavior_peekHeight="@dimen/bottom_sheet_peek_height"
        app:layout_behavior="@string/BottomSheetBehaviorGoogleMapsLike">

        <include
            layout="@layout/places_bottom_sheet"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true" />
    </android.support.v4.widget.NestedScrollView>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/places_fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        android:clickable="true"
        android:src="@drawable/ic_directions"
        app:elevation="3dp"
        app:layout_anchor="@id/bottom_sheet"
        app:layout_anchorGravity="top|right|end"
        app:layout_behavior="@string/ScrollAwareFABBehavior" />

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

这是来自BottomSheet“layout/places_bottom_sheet”的设计

<android.support.constraint.ConstraintLayout 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="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical"
    android:paddingBottom="16dp">

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="0dp" …
Run Code Online (Sandbox Code Playgroud)

android bottom-sheet android-constraintlayout

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

BottomSheetDialogFragment setupDialog 仅限于库组

我正在使用支持库中的BottomSheetDialogFragment,它警告我该函数setupDialog()只能在库组中使用。但这个函数是我初始化对话框的地方:

@Override
public void setupDialog(final Dialog dialog, int style) {
    super.setupDialog(dialog, style);
    FragmentArgs.inject(this);

    dialog.setOnShowListener(dialogINterface -> {
        if(dialog.getWindow() != null) {
            dialog.getWindow().setLayout(
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.MATCH_PARENT);
        }
    });

    BottomSheetStatisticsExportBinding binding = DataBindingUtil.inflate(
            LayoutInflater.from(getContext()),
            R.layout.bottom_sheet_statistics_export,
            null,
            false
    );

    View contentView = binding.getRoot();
    dialog.setContentView(contentView);

    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams();
    CoordinatorLayout.Behavior behavior = params.getBehavior();

    if( behavior != null && behavior instanceof BottomSheetBehavior )
        ((BottomSheetBehavior) behavior).setBottomSheetCallback(bottomSheetBehaviorCallback);

    for (Export export : exports)
        binding.flexbox.addView(new ExportItemView(getContext(), export));
}
Run Code Online (Sandbox Code Playgroud)

警告是因为我使用的是 super 方法。但我该怎么办呢?我应该将我的代码移到另一个函数中(onCreateDialog()onResume()...?),我应该删除对 …

android bottom-sheet

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

如何在BottomSheetDialog android的顶部中心添加关闭按钮?

想要在 BottomSheetDialog 上添加关闭按钮来关闭它。

我正在使用 BottomSheetDialog 的自定义视图(Linearlayout)。

filterDialog = new BottomSheetDialog(context); filterDialog.setContentView(rootView); filterDialog.getWindow().setWindowAnimations(R.style.CustomDialogAnimation); filterDialog.show();

下图是我的过滤器对话框:

在此输入图像描述

这就是我想要实现的目标:

在此输入图像描述

任何帮助将不胜感激。

android android-alertdialog bottom-sheet

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

使用 MaterialComponents 主题后的 BottomSheet 样式

最近我切换到使用com.google.android.material:material:1.0.0应用程序主题。

除了 set colorPrimary, colorPrimaryDarkand colorAccentusing MaterialButtonwith Widget.MaterialComponents.Buttonstyle 之外,activity/fragment和bottomSheetFragment中的按钮颜色不同!

在活动/片段中是可以的。但在BottomSheet中有不同的颜色(绿色)。

在此处输入图片说明

android android-styles material-design bottom-sheet material-components-android

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

带有皮肤的 BottomSheetDialogFragment 主题

如何将BottomSheetDialogFragment主题与其他主题结合?

我的应用程序具有使用主题制作的皮肤。BottomSheetDialogFragment应该有圆角,我使用以下方法实现:

 override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.CustomBottomSheetDialogTheme) /* hack to make background transparent */
 }
Run Code Online (Sandbox Code Playgroud)

然后在styles.xml

<style name="CustomBottomSheetStyle" parent="Widget.Design.BottomSheet.Modal">
    <item name="android:background">@android:color/transparent</item>
</style>

<style name="CustomBottomSheetDialogTheme" parent="Theme.MaterialComponents.Light.BottomSheetDialog">
    <item name="bottomSheetStyle">@style/CustomBottomSheetStyle</item>
</style>
Run Code Online (Sandbox Code Playgroud)

但是如果我从 扩展,Theme.MaterialComponents.Light.BottomSheetDialog我不会得到我在皮肤主题中定义的配色方案。

那么问题来了:如何在皮肤主题里面定义Dialog主题呢?

android android-theme bottom-sheet material-components material-components-android

4
推荐指数
2
解决办法
3262
查看次数

在BottomSheet中实现过渡

我正在尝试实现以下设计,但我似乎无法理解我应该这样做的方式:P

gif

我正在考虑BottomSheet通过showModalBottomSheet函数使用显示,但我无法弄清楚如何实现过渡(我将使用 aFadeTransition作为淡入淡出效果,但不知道高度变化效果)

到目前为止我得到了什么:

import 'package:flutter/material.dart';
import 'dart:math';

class Setup extends StatefulWidget {
  final Widget child;

  const Setup(this.child);

  @override
  _SetupState createState() => _SetupState();
}

class MyCurve extends Curve {
  @override
  double transform(double t) => -pow(t, 2) + 1;
}

class _SetupState extends State<Setup> with SingleTickerProviderStateMixin {
  AnimationController _controller;
  Animation<double> opacityAnimation;
  int i = 0;

  @override
  void initState() {
    super.initState();

    _controller =
        AnimationController(vsync: this, duration: Duration(milliseconds: 500));
    opacityAnimation = CurvedAnimation(
        parent: Tween<double>(begin: 1, end: 0).animate(_controller), …
Run Code Online (Sandbox Code Playgroud)

animation dart flutter bottom-sheet

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

无法膨胀并且没有找到android支持设计BottomSheetBehavior的类行为

我正在尝试在我的主要项目中实现底部模式表。我在一个演示项目中成功地做到了。但是当我将相同的结构应用于我的主项目时,应用程序崩溃并出现以下错误:

android.view.InflateException:二进制 XML 文件第 40 行:无法膨胀行为子类 android.support.design.widget.BottomSheetBehavior 由:java.lang.RuntimeException:无法膨胀行为子类 android.support.design.widget.BottomSheetBehavior

AndroidRuntime:引起:java.lang.ClassNotFoundException:在路径上找不到类“android.support.design.widget.BottomSheetBehavior”:DexPathList[[zip file“/data/app/com.example...... ..]]]

我尝试了之前app:layout_behavior="@string/bottom_sheet_behavior"在我的 xml 中所述的内容,但没有奏效。

在演示项目中,底部工作表在嵌套父视图中正常工作。

我的主要项目依赖项是 -(添加到 app build.gradle)

    def lifecycle_version = "2.1.0-alpha02"
    def room_version = "2.1.0-alpha04"
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'me.relex:circleindicator:2.1.0'
    implementation 'com.squareup.retrofit2:retrofit:2.5.0'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
    implementation 'com.github.chrisbanes:PhotoView:2.3.0'

    // ViewModel and LiveData
    implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
    annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
    implementation "androidx.room:room-runtime:$room_version"
    annotationProcessor "androidx.room:room-compiler:$room_version"
Run Code Online (Sandbox Code Playgroud)

android android-design-library androiddesignsupport bottom-sheet

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

BottomSheetDialogFragment 的生命周期是多少

我正在尝试将 Algolia 实现到 BottomSheetDialogFragment 中,并遇到一些我认为与生命周期相关的问题。我试图弄清楚生命周期是什么,但找不到答案。

如果有明显的原因要四处走动并获取该信息,我很抱歉,但我尝试查看文档但找不到它。

具体来说,我想知道何时调用 des onCreateDialog,以及该片段是否有其他独特的方法。我的问题是,由于某种原因,我的搜索框似乎与我的点击视图连接得不好(当我使用持久底部工作表时,相同的代码有效,但我必须更改),我想知道是否需要调用搜索器和我的代码中其他地方的助手。

android android-fragments android-dialogfragment algolia bottom-sheet

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

如何在颤振中动态降低底片高度?

我正在使用 showModalBottomSheet 并在开始时给出 90% 的高度。底页中有两个选项卡(重复和一次性),重复选项卡有很多内容,并且显示完美,高度为 90%。但是当我在一次性选项卡上打开选项卡时,我想将底页的大小减小到 40%,因为它没有更多内容,而且看起来不太好。但我无法在按下一次性选项卡按钮时动态更改底页的高度。

谁能帮助我如何在颤振中实现此功能?

dart flutter bottom-sheet flutter-showmodalbottomsheet

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