【问题标题】:Android Navigation Drawer & DialogAndroid 导航抽屉和对话框
【发布时间】:2015-03-08 07:33:44
【问题描述】:


是否可以显示 AlertDialog/DialogFragment 并保持导航抽屉打开?
我尝试了一个警报对话框和一个对话框片段,但抽屉突然关闭了。

警报对话框:

    new AlertDialog.Builder(this)
   .setTitle("Title")
   .setMessage("Message")
   .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int which) {
         // ...
      }
   })
   .setIcon(android.R.drawable.ic_dialog_alert)
   .show();

对话框片段:

public class NewTermDialogFragment extends DialogFragment {

private EditText lectureName;

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    LayoutInflater layoutInflater = getActivity().getLayoutInflater();
    View view = layoutInflater.inflate(R.layout.dialog_new_term, null);

    lectureName = (EditText) view.findViewById(R.id.lectureText);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(view);
    builder.setPositiveButton("Okay", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

        }
    });

    return builder.create();
}
}

呼叫:

FragmentManager fragmentManager = getFragmentManager();

NewTermDialogFragment newTermDialogFragment = new NewTermDialogFragment();
newTermDialogFragment.setCancelable(false);
newTermDialogFragment.show(fragmentManager, "Dialog!");

布局:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <LinearLayout xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <include layout="@layout/toolbar" />

        <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".RootActivity"
            tools:ignore="MergeRootFrame" />
    </LinearLayout>

    <fragment
        android:id="@+id/navigation_drawer"
        android:name="de.uni.kassel.studentenapp.fragments.NavigationDrawerFragment"
        android:layout_width="@dimen/navigation_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        tools:layout="@layout/fragment_navigation_drawer" />


</android.support.v4.widget.DrawerLayout>

【问题讨论】:

  • 您是否尝试从 NavigationDrawerFragment 本身显示它?
  • 哦,是的,它有效。不知道在fragment中调用UI-Elements是否可以。

标签: android android-fragments navigation-drawer android-alertdialog android-dialogfragment


【解决方案1】:

尝试从 NavigationDrawerFragment 显示它。它应该按应有的方式工作。

很高兴它有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-08
    • 1970-01-01
    相关资源
    最近更新 更多