gpt4 book ai didi

android - 向 BottomSheetDialogFragment 添加边距

转载 作者:行者123 更新时间:2023-12-04 12:10:31 27 4
gpt4 key购买 nike

我尝试向我的 BottomSheetDialogFragment 添加边距,但它对边距没有任何作用。

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="16dp">

<TextView
android:id="@+id/alertdialog_fragmail_newmessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test 1"
android:textStyle="bold"
android:padding="16dp"
android:textColor="@color/colorBlackFont"
android:layout_alignParentTop="true"
android:gravity="center_vertical"
android:drawablePadding="16dp"/>


//More Textviews

</RelativeLayout>

编辑:___________________________________________________

我已经尝试将 XML 更改为下面的答案,但是它仍然没有为我的 bottomsheetdialogfragment 创建边距。

底部工作表对话框 fragment 类的代码:
public class FragMailMoreDialog extends BottomSheetDialogFragment {

private static final String TAG = "FragMailMoreDialog";

private Context mContext;


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

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.alertdialog_layout_fragmailmore, container, false);
ButterKnife.bind(this, view);


return view;
}
}

充气底片的代码:
private void inflateMoreDialog(){
FragMailMoreDialog moreDialog = new FragMailMoreDialog();
if (getFragmentManager() != null) {
moreDialog.show(getFragmentManager(), "FRAGMAIL_MORE_DIALOG");
}
}

最佳答案

有点hacky的解决方案:

我将布局包裹在另一个 RelativeLayout 中,并使该布局的背景透明。

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

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorWhite"
android:layout_margin="16dp">

<TextView
android:id="@+id/alertdialog_fragmail_newmessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test 1"
android:textStyle="bold"
android:padding="16dp"
android:textColor="@color/colorBlackFont"
android:layout_alignParentTop="true"
android:gravity="center_vertical"
android:drawablePadding="16dp"
android:background="?attr/selectableItemBackground"/>
</RelativeLayout>
</RelativeLayout>

在 BottomSheetDialogFragment 中,您需要覆盖 setupDialog
@Override
public void setupDialog(Dialog dialog, int style) {
View contentView = View.inflate(getContext(), R.layout.alertdialog_layout_fragmailmore, null);
dialog.setContentView(contentView);
((View) contentView.getParent()).setBackgroundColor(getResources().getColor(android.R.color.transparent));
}

致谢此人:

https://stackoverflow.com/a/55219784/11110509

关于android - 向 BottomSheetDialogFragment 添加边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60679512/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com