【问题标题】:Rounded corners not working with Material Design Bottomsheet Android [duplicate]圆角不适用于 Material Design Bottomsheet Android [重复]
【发布时间】:2020-08-10 17:48:15
【问题描述】:

我正在使用 Material Design Library 1.1.0 并尝试在 Bottomsheet 上实现圆角。这是我的代码

风格-

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>

    <style name="DarkTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
        <item name="shapeAppearanceLargeComponent">@style/ShapeAppearance.An.LargeComponent
        </item>
        <item name="android:windowActivityTransitions">true</item>
    </style>

    <style name="SplashAppTheme" parent="Theme.AppCompat.NoActionBar">
        <!-- Customize your theme here. -->
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light">
        <item name="android:elevation">0dp</item>
    </style>

    <style name="ShapeAppearance.An.LargeComponent" parent="ShapeAppearance.MaterialComponents.LargeComponent">
        <item name="cornerFamily">rounded</item>
        <item name="cornerSize">4dp</item>
    </style>

</resources>

类-

public class LoadingFrag extends BottomSheetDialogFragment {
//Button
public LoadingFrag() {
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    return inflater.inflate(R.layout.bottom_sheet
            , container, false);
}

活动 XML-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/cardBackgroundColor"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:layout_gravity="center"
        android:gravity="start"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/textView4"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.7"
            android:fontFamily="@font/product_sans_bold"
            android:padding="20dp"
            android:text="@string/one_second"
            android:textAlignment="textStart"
            android:textColor="@color/primaryTextColorDark"
            android:textFontWeight="600"
            android:textSize="30dp"
            android:textStyle="bold" />

        <ProgressBar
            android:id="@+id/progressBar2"
            style="?android:attr/progressBarStyle"
            android:layout_width="wrap_content"
            android:layout_height="37dp"
            android:layout_gravity="center"
            android:layout_weight="0.3"
            android:indeterminate="true" />

    </LinearLayout>

    <TextView
        android:id="@+id/prem_id"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="-10dp"
        android:layout_marginBottom="20dp"
        android:fontFamily="@font/product_sans_regular"
        android:paddingStart="30dp"
        android:paddingRight="30dp"
        android:text="@string/we_are_processing_things_for_you_and_creating_a_signal_to_nuke_mars_just_kidding_wait"
        android:textColor="@color/primaryTextColor"
        android:textSize="16dp"
        app:lineHeight="25dp" />

</LinearLayout>

没有任何工作。我尝试手动创建一个形状并将其用作底片的形状,但这也不起作用。角落还是一样的。

任何帮助将不胜感激。

【问题讨论】:

    标签: android material-design bottom-sheet android-bottomsheetdialog


    【解决方案1】:

    如果您希望所有 4 个角都圆角,请在 BottomSheetDialogFragment 中, 覆盖此方法:

        @Override
        public void setupDialog(Dialog dialog, int style) {
                    View view = inflate your view here
    
                    ((View) view.getParent()).setBackgroundColor(ContextCompat.getColor(mContext, android.R.color.transparent));
    
                   }
    

    并在您的 xml 中将 MaterialCardView 设置为具有期望半径的父布局并尝试一下

    这里的想法是设置透明背景,这样卡片的半径就会显示出来。 有一些解决方案,但是这个技巧可以解决问题

    【讨论】:

    • 我只是想让上角不是全部四个。
    • 这是真的!对话框或底部工作表的父布局不得有背景以显示角形状
    猜你喜欢
    • 1970-01-01
    • 2014-05-22
    • 2017-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-25
    • 2016-07-28
    • 2016-06-23
    相关资源
    最近更新 更多