如果单击按钮,则在主 activity 上创建一个 slideUp window
Creating a slideUp window over the main activity if a button is clicked
我想创建一个 window,它会在单击按钮时弹出,我可以在其中提供一些可供选择的按钮,这些按钮可用于向主要 activity 提供一些数据.
我尝试了对话框和框架布局。对话框的问题是它没有覆盖整个屏幕。我面临的使用片段事务的框架布局问题是,当框架布局出现时,主要 activity 的布局也可见。
例如
但是当我点击按钮从下方显示 window 时:
即。 activity 中的图像和开始按钮也可见。它应该用我的片段 window 部分覆盖 activity 我已经尝试在 FrameLayout 中将背景颜色设置为白色。
您可以使用底部 sheet。
请在下面找到对您有帮助的教程link
告诉我,对你有没有帮助+1
试试这种代码方式来显示 window
public void showDefaultDialog() {
final Dialog dialog = new Dialog(MainActivity.this, android.R.style.Theme_Holo_Dialog);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().getAttributes().windowAnimations = R.style.animWindow;
dialog.setContentView(R.layout.dialogview);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.WHITE));
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}
将下面的代码行放入 style.xml 文件
<style name="animWindow">
<item name="@android:windowEnterAnimation">@anim/bottom_to_top</item>
<item name="@android:windowExitAnimation">@anim/top_to_bottom</item>
</style>
将下面这行代码放入drawable文件夹
- bottom_to_top.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="100%p"
android:toYDelta="0%p"
android:fillAfter="true"
android:duration="700" />
</set>
- top_to_bottom.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="0%p"
android:toYDelta="100%p"
android:fillAfter="true"
android:duration="700" />
</set>
您已经尝试使用 Dialog
,所以也许 BottomSheetDialogFragment
对您来说是个不错的选择,因为它从 DialogFragment
.
延伸而来
有一个 Medium 博客 post 有一个简短的例子:Using BottomSheetDialogFragment with Material Design Guideline
由于您需要全屏 Dialog
:BottomSheetDialogFragment - How to set expanded height (or min top offset) 是关于设置 BottomSheetDialogFragment
展开高度的 SO post。
另请参阅 material 关于 Modal Bottom Sheets as well as the reference
的设计指南
我想创建一个 window,它会在单击按钮时弹出,我可以在其中提供一些可供选择的按钮,这些按钮可用于向主要 activity 提供一些数据.
我尝试了对话框和框架布局。对话框的问题是它没有覆盖整个屏幕。我面临的使用片段事务的框架布局问题是,当框架布局出现时,主要 activity 的布局也可见。
例如
但是当我点击按钮从下方显示 window 时:
即。 activity 中的图像和开始按钮也可见。它应该用我的片段 window 部分覆盖 activity 我已经尝试在 FrameLayout 中将背景颜色设置为白色。
您可以使用底部 sheet。
请在下面找到对您有帮助的教程link
告诉我,对你有没有帮助+1
试试这种代码方式来显示 window
public void showDefaultDialog() {
final Dialog dialog = new Dialog(MainActivity.this, android.R.style.Theme_Holo_Dialog);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().getAttributes().windowAnimations = R.style.animWindow;
dialog.setContentView(R.layout.dialogview);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.WHITE));
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}
将下面的代码行放入 style.xml 文件
<style name="animWindow">
<item name="@android:windowEnterAnimation">@anim/bottom_to_top</item>
<item name="@android:windowExitAnimation">@anim/top_to_bottom</item>
</style>
将下面这行代码放入drawable文件夹
- bottom_to_top.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="100%p"
android:toYDelta="0%p"
android:fillAfter="true"
android:duration="700" />
</set>
- top_to_bottom.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="0%p"
android:toYDelta="100%p"
android:fillAfter="true"
android:duration="700" />
</set>
您已经尝试使用 Dialog
,所以也许 BottomSheetDialogFragment
对您来说是个不错的选择,因为它从 DialogFragment
.
有一个 Medium 博客 post 有一个简短的例子:Using BottomSheetDialogFragment with Material Design Guideline
由于您需要全屏 Dialog
:BottomSheetDialogFragment - How to set expanded height (or min top offset) 是关于设置 BottomSheetDialogFragment
展开高度的 SO post。
另请参阅 material 关于 Modal Bottom Sheets as well as the reference
的设计指南