【问题标题】:Modal Bottom Sheet isnt transparent althought background set too transparent尽管背景设置为透明,但模态底页不透明
【发布时间】:2019-09-20 13:30:28
【问题描述】:

我所有的模态 BottomSheets 上方都有一个白色背景,并且不像预期的那样透明。

我尝试通过这样的单独片段打开视图:

 ContextMenuPlaylistFragment contextMenuPlaylistFragment = new ContextMenuPlaylistFragment();
 contextMenuPlaylistFragment.show(fragmentManager,"contextmenu playlists");

像这样:

View modelBottomSheet = LayoutInflater.from(mContext).inflate(R.layout.context_menu_playlist, null);
BottomSheetDialog dialog = new BottomSheetDialog(mContext);
dialog.setContentView(modelBottomSheet);
dialog.show();

这是我的 BottomSheetFragment:

public class ContextMenuPlaylistFragment extends BottomSheetDialogFragment {

    @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.context_menu_playlist, container, false);
    }
}

这是我的底页:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/transparent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:gravity="center_horizontal"
        android:orientation="vertical"
        android:padding="16dp">




        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/button_playlist_search"
            android:orientation="horizontal"
            android:layout_marginBottom="15dp">
            <ImageView
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:src="@drawable/ic_search_black_24dp" />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/search_playlist"
                android:textSize="18sp"
                android:layout_marginStart="10dp"
                android:textStyle="bold" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/button_playlist_rename"
            android:orientation="horizontal"
            android:layout_marginBottom="15dp">
            <ImageView
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:src="@drawable/ic_edit_black_24dp" />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/rename_playlist"
                android:textSize="18sp"
                android:layout_marginStart="10dp"
                android:textStyle="bold" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
        android:id="@+id/button_playlist_delete"
            android:orientation="horizontal"
            android:layout_marginBottom="15dp">
            <ImageView
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:src="@drawable/ic_delete_black_24dp" />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/delete_playlist"
                android:textSize="18sp"
                android:layout_marginStart="10dp"
                android:textStyle="bold" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

我将它放在两个 LinearLayouts 中以尝试使背景透明。 我还尝试了一个LinearLayout,它不会改变背景并且具有高度"wrap_content"

【问题讨论】:

  • 您的应用中是否使用了材质主题?
  • 你想用透明背景制作全屏吗?
  • 是的,我在我的应用程序中使用了一个材质主题,不,我想让它达到带有透明背景的 wrap_content 的高度

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


【解决方案1】:

请检查您是否将“AppTheme”样式中的android:background 属性设置为白色。如果是这样,将其删除或将其设置为透明即可解决问题。

【讨论】:

    猜你喜欢
    • 2012-07-27
    • 2012-01-29
    • 1970-01-01
    • 1970-01-01
    • 2018-02-20
    • 2018-12-25
    • 2016-10-09
    • 1970-01-01
    • 2022-11-13
    相关资源
    最近更新 更多