我刚刚开始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
我目前通过 a 显示底部工作表BottomSheetScaffold,并希望当用户在底部工作表外部单击时折叠它。有没有办法检测底页之外的点击?
这是我的屏幕BottomSheetScaffold:
@ExperimentalMaterialApi
@ExperimentalMaterial3Api
@Composable
fun HomeScreen() {
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState(
bottomSheetState = BottomSheetState(BottomSheetValue.Collapsed)
)
val coroutineScope = rememberCoroutineScope()
BottomSheetScaffold(
scaffoldState = bottomSheetScaffoldState,
sheetContent = {
Box(
Modifier
.fillMaxWidth()
.fillMaxHeight(0.9f)
) {
Text("Hello from Sheet")
}
},
sheetShape = RoundedCornerShape(
topStart = Spacing.l,
topEnd = Spacing.l
),
sheetPeekHeight = LocalConfiguration.current.screenHeightDp.dp * 0.15f,
sheetBackgroundColor = MaterialTheme.colorScheme.surface,
) {
Scaffold() {
Button(
onClick = {
coroutineScope.launch {
if (bottomSheetScaffoldState.bottomSheetState.isCollapsed) {
bottomSheetScaffoldState.bottomSheetState.expand()
} else {
bottomSheetScaffoldState.bottomSheetState.collapse() …Run Code Online (Sandbox Code Playgroud) android kotlin bottom-sheet android-jetpack-compose android-jetpack-compose-scaffold
我在坐标布局中有一个 BottomSheet。在正常情况下完美运行。当 Android 使用屏幕手势而不是导航按钮时,会出现问题。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/episode_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
app:behavior_hideable="false"
app:behavior_peekHeight="0dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
Run Code Online (Sandbox Code Playgroud)
使用手势导航时
我已经尝试过否定,app:behavior_peekHeight但它不起作用。但当我给出 app:behavior_peekHeight="@dimen/_45sdp"它时,它显示播放器控制器,但也显示底部布局。我想隐藏底部布局。
标准android BottomSheetBehavior具有树状态:隐藏,折叠和扩展。
我想允许用户在折叠和展开之间“保留”底页。现在,使用默认行为,它将根据最接近的位置捕捉到折叠或展开。我应该如何禁用此捕捉功能?
我在LinearLayout中有一个带有BottomSheetBehavior的两个RecyclerView.当您单击第一个RecyclerView内的项目(带网格)时,RecyclerView将设置为Gone,并显示第二个RecyclerView(带有列表).当显示第二个Recycler时,您无法上下滑动BottomSheet而不是List即使在Expanded State中也在滚动.如果First Recycler已经上市,一切都很好.有没有办法让BottomSheet再次上下滑动?
<LinearLayout
android:id="@+id/sliding_layout_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical"
app:behavior_hideable="false"
app:behavior_peekHeight="400dp"
app:layout_behavior="@string/bottomSheetBehavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:background="@color/white"
android:clickable="true"
android:scrollbars="none" />
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:background="@color/white"
android:clickable="true"
android:scrollbars="none" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
GridAdapter:
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
String categorieName = mCategories.get(position);
final CategoryFilterEvent event = new CategoryFilterEvent(categorieName);
holder.grid_item_label.setText(categorieName);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EventBus.getDefault().post(event);
}
});
}
Run Code Online (Sandbox Code Playgroud)
主要活动:
@Override
public void onCreate(Bundle savedInstanceState) {
linearLayoutManager = new LinearLayoutManager(this);
listAdapter = …Run Code Online (Sandbox Code Playgroud) 假设我的“底部工作表”中包含以下几行小部件。如果我想只显示前两行(即前两行LinearLayout),而不显示下面的其余小部件。我不希望这些内容一开始就被看到。如何设置正确的窥视高度?硬编码app:behavior_peekHeight可能无法工作,因此我需要以编程方式进行设置,但是如何计算高度呢?
还是有更推荐的方法来获得相同的结果?我的意思是,如果我测试Google Maps,长按位置会首先仅将标题部分显示为底部,但是当我尝试向上滚动底部时,感觉好像标题部分(可能不是真正的标题部分)底页)替换为包含所有元素的真实底页。如果我的解释还不够,请自己尝试使用Google地图。
<android.support.v4.widget.NestedScrollView
android:id="@+id/bottom_sheet"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView/>
<android.support.v7.widget.AppCompatSpinner/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView/>
<TextView/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView/>
<TextView/>
</LinearLayout>
<android.support.v7.widget.RecyclerView/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud) 我正在通过Flutter Gallery查看与CupertinoPicker相关的代码.
这是相关的代码提取:
child: new GestureDetector(
// Blocks taps from propagating to the modal sheet and popping.
// onTap: () { },
child: new SafeArea(
child: new CupertinoPicker(
scrollController: scrollController,
itemExtent: _kPickerItemHeight,
backgroundColor: CupertinoColors.white,
onSelectedItemChanged: (int index) {
setState(() {
print(_selectedItemIndex);
_selectedItemIndex = index;
});
},
children: new List<Widget>.generate(coolColorNames.length, (int index) {
return new Center(child:
new Text(coolColorNames[index]),
);
}),
),
),
),
Run Code Online (Sandbox Code Playgroud)
现在,我需要一个回调/监听器,当CupertinoPicker关闭时,换句话说,当用户做出选择并且他的选择是最终的时候,我需要知道他的最终选择是什么.
这里的用例是我想在底片关闭时根据他的最终选择进行api回调.
目前,由于只有onSelectedItemChanged的回调,因此我只能在用户旋转选择器时获取值.见下面的gif.
我看到BottomSheet小部件有一个onClosing回调:https://docs.flutter.io/flutter/material/BottomSheet-class.html
但是我很困惑如何获得它的实例,因为Flutter Gallery样本使用以下代码调用底层,并且没有方法从代码中获取底层:
new GestureDetector(
onTap: () async {
await showModalBottomSheet<void>(
context: context, …Run Code Online (Sandbox Code Playgroud) BottomSheetDialogFragment当我打开它时,我打开一半(意思是不完全).
fragment.show(supportFragmentManager, "my_frag")
Run Code Online (Sandbox Code Playgroud)
NestedScrollView过behavior_peekHeight但没有奏效.NestedScrollView.只有LinearLayout.match_parent&之间尝试切换高度wrap_content我有简单RecyclerView的BottomSheetDialogFragment布局.
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
...
>
<android.support.v7.widget.RecyclerView
...
/>
Run Code Online (Sandbox Code Playgroud) 我在底部使用开关时遇到了一些问题.当我点击它时,它不会改变它的状态.只是第一次,状态正确改变.
这是我正在使用的简单代码:
bool _switchValue = false;
@override
Widget build(BuildContext context)
{
return new Scaffold(
body: Center(
child: RaisedButton(
child: const Text('SHOW BOTTOM SHEET'),
onPressed: () {
showModalBottomSheet<void>(context: context, builder: (BuildContext context) {
return Container(
child: CupertinoSwitch(
value: _switchValue,
onChanged: (bool value) {
setState(() {
_switchValue = value;
});
},
)
);
});
}
)
)
);
}
Run Code Online (Sandbox Code Playgroud)
谁能帮帮我吗?
我可以使用打开我的BottomSheetDialogFragment
val bottomSheet = BottomSheetFragment()
bottomSheet.show(fragmentManager!!, "BottomSheet")
Run Code Online (Sandbox Code Playgroud)
但它只打开以显示其内容的一半-我希望它在打开时可以扩展到屏幕的整个高度,而无需向上拖动。
我环顾四周,似乎一种方法是将BottomSheetBehavior状态设置为STATE_EXPANDED,但是我无法在Kotlin中找到解决方法。
任何帮助,将不胜感激!