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开脚本视频,哈糖大菠萝辅助器,曝光教程(有挂透明)》 哈糖大菠萝辅助器软件...
带你了解!pokemomo辅助... 1、带你了解!pokemomo辅助工具,wejoker透视方法,曝光教程(有挂教程)2、进入游戏-大...
热点讨论!wepoker正确养... 1、热点讨论!wepoker正确养号方法,约局吧透视挂下载,德州教程(有挂技巧)。2、wepoker...
分享开挂内幕!hhpoker可... 1、分享开挂内幕!hhpoker可以开挂吗,werplan怎么作弊,详细教程(有挂软件);详细教程。...
2024教程!德普之星辅助器怎... 《2024教程!德普之星辅助器怎么用,约局吧app有挂吗,透牌教程(有挂透视)》 德普之星辅助器怎么...
记者揭秘!pokermaste... 记者揭秘!pokermaster脚本,大菠萝免费辅助器,2025新版总结(有挂方法)1、点击下载安装...
今日头条!hhpoker免费辅... 今日头条!hhpoker免费辅助器,pokemmo手机版透视脚本,wepoke教程(有挂方法);致您...
分享个大家!哈糖大菠萝破解器,... 分享个大家!哈糖大菠萝破解器,we poker游戏下,新版2025教程(有挂技巧);亲真的是有正版授...
一分钟揭秘!pokemmo内置... 一分钟揭秘!pokemmo内置修改器,xpoker辅助器,可靠教程(有挂方法)关于pokemmo内置...
揭秘关于!德州hhpoker脚... 揭秘关于!德州hhpoker脚本,wepoker插件下载,解密教程(有挂软件);玩家必备必赢加哟《1...