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");

相关内容

热门资讯

透视机巧!poker worl... 透视机巧!poker world辅助,WePoKer规律好像是真的有神器,9分钟教程(有挂技巧)1、...
脚本推荐!有哪些免费的wpk作... 脚本推荐!有哪些免费的wpk作必弊码,wpk辅助软件(透视)都是存在有攻略(哔哩哔哩)能透视中分为三...
脚本解密!aa poker透视... 脚本解密!aa poker透视软件,aapoker透视脚本(透视)果然真的是有神器(哔哩哔哩)1、每...
透视总结!pokeplus脚本... 透视总结!pokeplus脚本,微乐自建房脚本如何下载,解密脚本(有挂教程)-哔哩哔哩;1)poke...
透视安装!拱趴大菠萝开挂方法,... 透视安装!拱趴大菠萝开挂方法,微乐自建房免费黑科技下载,专业透视(有挂秘诀)-哔哩哔哩拱趴大菠萝开挂...
透视揭露!aapoker怎么设... 透视揭露!aapoker怎么设置提高好牌几率,aapoker怎么设置抽水(透视)一贯有app(哔哩哔...
透视有挂!wpk有作必弊吗,w... 透视有挂!wpk有作必弊吗,wpk刷入池率脚本(透视)确实存在有脚本(哔哩哔哩)1、免费辅助多个强度...
透视软件!wepoker透视脚... 透视软件!wepoker透视脚本下载,陕西微乐小程序攻略,总结透视(有挂详细)-哔哩哔哩1、每一步都...
不少玩家反映!aapoker辅... 不少玩家反映!aapoker辅助怎么用,微乐小程序免费黑科技5个玩家常用方法,专业透视(有挂教程)-...
透视有挂!德普之星透视辅助软件... 透视有挂!德普之星透视辅助软件是真的吗,德普辅助软件(透视)好像是有挂(哔哩哔哩)1、上手简单,内置...