#android-studio #android-layout #android-bottomsheetdialog
Вопрос:
Я пытаюсь сделать прозрачный фоновый заголовок для кнопки закрытия. Заголовок фона работает так, как ожидалось, однако макет фона виден, а кнопка также неясна.
Я пытаюсь построить так, как показано на рисунке ниже
Мой код выглядит следующим образом:
Код деятельности
final BottomSheetDialog dialog = new BottomSheetDialog(this, R.style.BottomSheetMainStyle);
`dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
`dialog.show();
Код компоновки
<RelativeLayout 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="match_parent"
android:background="@android:color/transparent"
android:gravity="center|top"
android:orientation="vertical">
<ImageView
android:id="@ id/img_close"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:background="@android:color/transparent"
android:clickable="true"
android:forceDarkAllowed="false"
android:paddingBottom="@dimen/dimen_8"
android:src="@drawable/bottom_close"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_below="@id/img_close"
android:background="@drawable/rounded_dialog"
app:background="@color/bkgcolor"
android:orientation="vertical">
<!-- All your required widgets here-->
</RelativeLayout>
</RelativeLayout>
Ответ №1:
Код деятельности
final BottomSheetDialog dialog = new BottomSheetDialog(this, R.style.trans_bg_dialog);
`dialog.show();
Добавьте это в свой style.xml файл
<style name="trans_bg_dialog" parent="@style/Theme.AppCompat.Dialog">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
</style>