使用标题&创建全屏对话框取消/确定按钮

时间:2017-08-30 10:42:15

标签: java android dialog android-dialogfragment

我正在尝试进行类似于此的对话:

Costum full screen dialog example

但Android Developer Guide和我看到的问题都无法解决我的问题:

  1. 标题没有显示,我只是得到了我的服装布局。

  2. 我不知道如何在左边放一个“x”,在右边放一个Save-Icon!它应该适用于WINDOW FEATURES ??

  3. 对话片段代码:

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.dialogfragment_statsentry, container, false);
    }
    
    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog mDialog = super.onCreateDialog(savedInstanceState);
        mDialog.setTitle("hello");
        return mDialog;
    }
    
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }
    

    dialogfragment XML:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:minWidth="600dp"
        android:layout_height="match_parent"
        android:minHeight="400dp"
        android:orientation="vertical"
        android:padding="10dp">
    
        <TextView
            android:id="@+id/dialog_statsentry_txvTime"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <android.support.design.widget.TextInputEditText
                android:id="@+id/dialog_statsentry_edtName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPersonName" />
        </android.support.design.widget.TextInputLayout>
    
    </LinearLayout>
    

    我如何调用对话框:

    StatsEntryFragmentDialog mFragment = new StatsEntryFragmentDialog();
    
    FragmentManager mManager = getSupportFragmentManager();
    
    if (Utils.isTablet(getApplicationContext())) {
        mFragment.show(mManager, mFragment.TAG); // no fullscreen for bigger displays
    }
    else {
        FragmentTransaction mTransaction = mManager.beginTransaction();
        mTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    
        mTransaction.add(CONTENT_CONTAINER, mFragment).addToBackStack(mFragment.TAG).commit();
    }
    

    提前致谢!

1 个答案:

答案 0 :(得分:2)

尝试使用Window编写对话框的高度和宽度,如下面的代码

Window window = customDialog.getWindow();
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
window.setGravity(Gravity.CENTER);
customDialog.show();