java - 如何使底部工作表对话框的角变圆?
问题描述
我试图使我的 BottomSheetDialog 的顶角变圆,但我在网上没有任何运气。这就是我希望它看起来的样子:
无论我尝试了什么,我都会得到这个:
我已经尝试过这里的方法并使用 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>
底部导航菜单片段:
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);
}
}
这就是我展示片段的方式:
BottomNavMenuFragment navFragment = new BottomNavMenuFragment();
navFragment.show(getSupportFragmentManager(), navFragment.getTag());
我似乎没有做任何事情。有人能指出我正确的方向吗?
解决方案
按照以下步骤获得顶部圆角底片:
第 1 步: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>
第2步:创建以下样式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>
第 3 步:BottomNavMenuFragment
在课堂上添加样式
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NORMAL, R.style.BottomSheetDialogStyle);
}
就是这样,样式将应用于底页。
推荐阅读
- svg - Paper.js 如何将一条路径变形为另一条路径?
- r - geom_bar 图与 position="dodge" 和 geom_text 重复值
- json - 将 neo4j 查询导出为 JSON、CSV 或 GraphML,包括节点和关系
- node.js - 使用 semver 包判断版本是否匹配
- sql-server - TSQL评估连接字符串表中的表达式
- c++ - 是否可以在 pion 中有动态路由?
- c# - 检查 unicode 字符是什么类型的字符
- sharepoint - 使用 Sharepoint Office 365 显示数据
- csv - 如何使用 CSVProvider 加载具有不同结构的 csv?
- websocket - HttpListenerContext.AcceptWebSocketAsync 错误 1229