我如何听取最后解雇BottomSheetDialogFragment?我想在最终解雇时保存用户更改...
我试过以下:
方法1
如果通过向下滑动对话框解除对话(不在背面按压或外面触摸),则仅触发此操作
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
Dialog d = super.onCreateDialog(savedInstanceState);
d.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
BottomSheetDialog d = (BottomSheetDialog) dialog;
FrameLayout bottomSheet = (FrameLayout) dialog.findViewById(android.support.design.R.id.design_bottom_sheet);
BottomSheetBehavior behaviour = BottomSheetBehavior.from(bottomSheet);
behaviour.setState(BottomSheetBehavior.STATE_EXPANDED);
behaviour.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_HIDDEN)
{
// Bottom Sheet was dismissed by user! But this is only fired, if dialog is swiped down! Not if touch outside dismissed the …Run Code Online (Sandbox Code Playgroud) android dialog android-dialogfragment dialogfragment bottom-sheet
我有一个BottomSheetView具有animateLayoutChanges="true".最初它显示很好.但如果将visibility视图(内部BottomSheetView)更改GONE为VISIBLE,则应用程序会混乱计算并BottomSheetView移动到屏幕顶部.我试过设置布局layout_gravity=bottom的根目录BottomSheetView.但没有成功.
BottomSheetView在改变任何视图的可见性之前,我有我的图像.(点击图片查看完整尺寸)
更改视图的可见性(GONE到VISIBLE或VISIBLE到GONE)后,我的BottomSheetView移动到顶部.(点击图片查看完整尺寸)
我猜,Android在计算视图width和测量时会搞乱height.有什么办法解决这个问题?
我也试图让我的BottomSheetView完全延伸至父视图匹配,但不知何故,即拍即height的BottomSheetView比手机屏幕和-TUN创建滚动问题更长.
预期的解决方案:
1> BottomSheetView即使visibility视图改变,也要防止改变其位置.
要么
2>使BottomSheetView匹配成为父级,以便在弄乱计算后看起来不会很糟糕.
animation android android-layout android-fragments bottom-sheet
我使用此解决方案和此库在onCreate()的活动中实现了Bottom Sheet功能
sheet = new BottomSheet.Builder(this, R.style.BottomSheet_Dialog)
.title("New")
.grid() // <-- important part
.sheet(R.menu.menu_bottom_sheet)
.listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO
}
}).build();
Run Code Online (Sandbox Code Playgroud)
现在,我想显示底部工作表,点击按钮并以同样的方式想要隐藏底部工作表点击同一个按钮,如果已经可见
我已经实现了一个BottomSheet对话框,我希望当用户在偷看时(未完全展开状态)触摸底部外面时防止底片消失.
我已经设置dialog.setCanceledOnTouchOutside(false);了代码,但它似乎没有任何影响.
这是我的BottomSheetDialogFragment类:
public class ShoppingCartBottomSheetFragment 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.fragment_shopping_cart_bottom_sheet, null);
dialog.setCanceledOnTouchOutside(false);
dialog.setContentView(contentView);
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams();
CoordinatorLayout.Behavior behavior = params.getBehavior();
if( behavior != null && behavior …Run Code Online (Sandbox Code Playgroud) BottomSheetDialog在应用程序之间切换时,背景闪烁.我究竟做错了什么 ?
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn1).setOnClickListener(v -> {
BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(MainActivity.this);
bottomSheetDialog.setContentView(R.layout.content);
bottomSheetDialog.show();
});
}
}
Run Code Online (Sandbox Code Playgroud)
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
content.xml文件
<?xml version="1.0" encoding="utf-8"?>
<View xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#F00" />
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.holtaf.testandroidapplication">
<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar">
<activity android:name=".MainActivity"> …Run Code Online (Sandbox Code Playgroud) 我正在使用Google Design Support Library 25.0.0在我的活动中,我有一个相对布局
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
Run Code Online (Sandbox Code Playgroud)
现在当我引用它来添加BottomSheetBehaviour时,我收到错误
java.lang.IllegalArgumentException: The view is not associated with BottomSheetBehavior
Run Code Online (Sandbox Code Playgroud)
这是布局:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/maps_colayout"
xmlns:app="http://schemas.android.com/tools"
android:fitsSystemWindows="true"
android:background="@color/white">
...
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="280dp"
android:layout_gravity="bottom"
android:id="@+id/rl_bottomsheet"
android:background="#F3F3F3"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
...
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这是活动相关代码:
CoordinatorLayout colayout = (CoordinatorLayout) findViewById(R.id.maps_colayout);
View bottomSheet = colayout.findViewById(R.id.rl_bottomsheet);
BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
// React to state change
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
// React to dragging …Run Code Online (Sandbox Code Playgroud) android android-design-library androiddesignsupport bottom-sheet
如何BottomSheetDialog(Fragment)使用ToolBar 创建一个切换到全屏的模态,如材料设计规范中所示?
我可以通过添加a BottomSheetBehavior.BottomSheetCallback并根据slideOffset设置ToolBar的alpha来手动添加ToolBar.移动底板时,这有点像hacky但似乎有效.但是,当我的底部工作表包含EditText并显示键盘时,这不起作用.我尝试了两个版本:BottomSheetDialogFragment并手动将行为添加到新片段.
我已经尝试了新BottomSheetBehaviour的设计库23.0.2,但我认为它太有限了.当我用setState()方法更改状态时,底部图片使用广告动画移动到新状态.
如何在没有动画的情况下立即更改状态?我没有看到公开的方法来做到这一点.
android android-design-library android-coordinatorlayout bottom-sheet
键盘下方还有更多字段.这发生在我更新支持库时.我知道它是Kotlin但它看起来几乎和java一样.我该如何解决这个问题?
这就是它的样子:
我的代码:
class ProjectsEditBottomSheetFragment(val privateID: String,
val publicID: String) : BottomSheetDialogFragment() {
private val mBottomSheetBehaviorCallback = object : BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(bottomSheet: View, newState: Int) {
if (newState == BottomSheetBehavior.STATE_HIDDEN) {
dismiss()
}
}
override fun onSlide(bottomSheet: View, slideOffset: Float) {
if (slideOffset < -0.15f) {
dismiss()
}
}
}
override fun setupDialog(dialog: Dialog, style: Int) {
super.setupDialog(dialog, style)
val view = View.inflate(context, R.layout.projects_edit_sheet, null)
dialog.setContentView(view)
dialog.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
val params = (view.parent as View).layoutParams as CoordinatorLayout.LayoutParams
val behavior = …Run Code Online (Sandbox Code Playgroud) android android-softkeyboard android-fragments kotlin bottom-sheet