gpt4 book ai didi

java - 如何使底部工作表对话框的角变圆?

转载 作者:行者123 更新时间:2023-12-04 01:24:43 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Round corner for BottomSheetDialogFragment

(26 个回答)


5个月前关闭。




我试图让我的 BottomSheetDialog 的顶角变圆,但我在网上没有任何运气。这就是我希望它看起来的样子:

Rounded Modal Bottom Sheet

无论我尝试了什么,我都会得到这个:

Not rounded Modal Bottom Sheet

我试过here的方法并使用 shapeAppearanceLargeComponent (我现在正在使用)。

这是我的代码:

样式.xml

 <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
...
<item name="shapeAppearanceLargeComponent">@style/CustomShapeAppearanceBottomSheetDialog</item>
</style>

<style name="CustomShapeAppearanceBottomSheetDialog" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSizeTopRight">16dp</item>
<item name="cornerSizeTopLeft">16dp</item>
</style>

底部导航菜单 fragment :
public class BottomNavMenuFragment extends BottomSheetDialogFragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_bottom_nav_drawer, container, false);
}
}

这就是我展示 fragment 的方式:
BottomNavMenuFragment navFragment = new BottomNavMenuFragment();
navFragment.show(getSupportFragmentManager(), navFragment.getTag());

我似乎没有做任何事情。有人能指出我正确的方向吗?

最佳答案

按照以下步骤获得顶部圆角底片:

第一步:创建可绘制 rounded_top_corners.xml drawable 内的文件文件夹

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/white"/>
<corners android:topLeftRadius="8dp"
android:topRightRadius="8dp"/>
</shape>

第二步:styles.xml 中创建以下样式
 <style name="BottomSheetDialogStyle" parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">@style/bottomSheetBackground</item>
</style>

<style name="bottomSheetBackground" parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">@drawable/rounded_top_corners</item>
</style>

第三步:BottomNavMenuFragment 中添加样式类(class)
 @Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NORMAL, R.style.BottomSheetDialogStyle);
}

就是这样,样式将应用于底页。

关于java - 如何使底部工作表对话框的角变圆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62100100/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com