Spe*_*ont 6 java android material-design android-bottomsheetdialog
我试图使我的 BottomSheetDialog 的顶角变圆,但我在网上没有任何运气。这就是我希望它的样子:

无论我尝试过什么,我都不断得到这个:

我在这里尝试过该方法并使用 shapeAppearanceLargeComponent (我现在正在使用的)。
这是我的代码:
样式文件
<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>
Run Code Online (Sandbox Code Playgroud)
底部导航菜单片段:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我展示片段的方式:
BottomNavMenuFragment navFragment = new BottomNavMenuFragment();
navFragment.show(getSupportFragmentManager(), navFragment.getTag());
Run Code Online (Sandbox Code Playgroud)
我似乎没有做任何工作。有人能指出我正确的方向吗?
按照以下步骤获得顶部圆角底片:
第 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>
Run Code Online (Sandbox Code Playgroud)
第 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>
Run Code Online (Sandbox Code Playgroud)
第 3 步:在BottomNavMenuFragment类中添加样式
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NORMAL, R.style.BottomSheetDialogStyle);
}
Run Code Online (Sandbox Code Playgroud)
就是这样,样式将应用于底部。
| 归档时间: |
|
| 查看次数: |
4133 次 |
| 最近记录: |