AndroidStudio中看不到DialogFragment
创始人
2024-08-21 00:00:25
0
  1. 确认 Dialog Fragment 的布局文件是否正确,是否包含正确的视图元素。
  2. 在应用程序代码中,确保正确地实例化 Dialog Fragment 并将其添加到 Activity 或 Fragment 的视图层次结构中。
  3. 确保在Fragment中使用getChildFragmentManager(),在Activity中使用getSupportFragmentManager()。 示例代码:
  4. 布局文件





  1. 创建 Dialog Fragment:

public class MyDialogFragment extends DialogFragment { private EditText mEditText; private String mText;

public MyDialogFragment() {
    // Required empty public constructor
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Get the layout inflater
    LayoutInflater inflater = getActivity().getLayoutInflater();

    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_my_dialog, null);

    mEditText = (EditText) view.findViewById(R.id.editText);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(view)
            .setTitle("Dialog Fragment Title")
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    mText = mEditText.getText().toString();
                }
            })
            .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // do nothing
                }
            });
    AlertDialog dialog = builder.create();
    setCancelable(false);
}

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    return super.onCreateDialog(savedInstanceState);
}

}

  1. 在 Activity 中调用 Dialog Fragment

MyDialogFragment dialogFragment = new MyDialogFragment(); dialogFragment.show(getSupportFragmentManager(), "dialog");

相关内容

热门资讯

随着!WePOker有没有透视... 随着!WePOker有没有透视方法,花城牌舍辅助系统有哪些功能,一直存在有辅助教程(哔哩哔哩)一、花...
今年以来!wepoker透视功... 今年以来!wepoker透视功能下载,蘑菇辅助网,总是存在有辅助app(哔哩哔哩)1、首先打开蘑菇辅...
据报道!we poker插件,... 据报道!we poker插件,小程序跑的快辅助器,切实有辅助技巧(哔哩哔哩)1、操作简单,无需小程序...
最终!wejoker辅助机器人... 最终!wejoker辅助机器人,吉祥填大坑有插件吗,本来真的有辅助软件(哔哩哔哩)吉祥填大坑有插件吗...
网友热议!wepoker买脚本... 网友热议!wepoker买脚本靠谱吗,一起宁德游戏钓蟹黑科技,果然是有辅助app(哔哩哔哩)1、一起...
事发当天!德普之星透视辅助软件... 事发当天!德普之星透视辅助软件下载,微信途游辅助,一直是有辅助技巧(哔哩哔哩)1、进入游戏-大厅左侧...
连日来!约局吧是否有挂,爱趣玩... 连日来!约局吧是否有挂,爱趣玩辅助,一贯是真的有辅助软件(哔哩哔哩)1、完成约局吧是否有挂辅助器v3...
据相关数据显示!hhpoker... 据相关数据显示!hhpoker万能辅助器,xpoker辅助,总是存在有辅助技巧(哔哩哔哩)1)xpo...
备受关注的!德普之星app安卓... 备受关注的!德普之星app安卓版破解版,随意玩有没有辅助,竟然存在有辅助方法(哔哩哔哩)1、进入游戏...
迎来新发展!wepoker私局... 迎来新发展!wepoker私局代打,小程序广东雀神智能挂件,本来是真的有辅助脚本(哔哩哔哩)1、下载...