这是一个问题。我创建了一个从下到上显示的对话框,并保持在屏幕的底部。定制aosp或LG股票roms是可以的,但在Nexus设备上,它在没有对话框内容的地方显示奇怪的人工制品。
一些代码:
public class BottomDialog extends DialogFragment implements MiniFragmentsCallback {
public enum DialogType {SHIPPING, BILLING}
private static final String DIALOG_TYPE = "dialog_type";
private DialogType dialogType;
@Setter
private DataListener dataListener;
public static BottomDialog newInstance(DialogType type, DataListener listener) {
BottomDialog dialog = new BottomDialog();
Bundle b = new Bundle();
b.putSerializable(DIALOG_TYPE, type);
dialog.setArguments(b);
dialog.setDataListener(listener);
return dialog;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
return dialog;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.style.FullScreenDialog);
}
@Override
public void onStart() {
super.onStart();
Dialog dialog = getDialog();
if (dialog != null) {
Window window = dialog.getWindow();
if (window != null) {
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT);
}
}
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Window window = getDialog().getWindow();
WindowManager.LayoutParams wl = window.getAttributes();
wl.x = 0;
wl.y = getActivity().getWindowManager().getDefaultDisplay().getHeight();
wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;
return View.inflate(getActivity(), R.layout.bottom_dialog_layout, container);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getChildFragmentManager().beginTransaction()
.replace(R.id.container, getDialogType()).commit();
}
}
风格:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:paddingTop="56dp">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
</LinearLayout>
主题:
<style name="FullScreenDialog">
<item name="android:windowAnimationStyle">@style/DialogAnimationStyle</item>
<item name="android:windowTranslucentStatus" tools:targetApi="kitkat">true</item>
</style>