gpt4 book ai didi

android - 如何在android中显示DialogFragment android.support.v4.app.DialogFragment

转载 作者:行者123 更新时间:2023-11-29 14:31:49 25 4
gpt4 key购买 nike

我是 fragment 的新手。我想在对话框中显示图像。任何人都可以提供代码 fragment 来说明如何显示支持所有设备的 DialogFragment 吗?

最佳答案

制作一个布局文件并将您的图像放入其中(例如 dialog_fragment.xml)。
制作您的对话 fragment (例如 MyDialogFragment.java)

import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;

public class MyDialogFragment extends DialogFragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_fragment, container);
// This shows the title, replace My Dialog Title. You can use strings too.
getDialog().setTitle("My Dialog Title");
// If you want no title, use this code
// getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

return view;
}
}

导入:import android.support.v4.app.FragmentManager;

FragmentManager fm = getSupportFragmentManager();
MyDialogFragment myDialogFragment = new MyDialogFragment();
myDialogFragment.show(fm, "dialog_fragment");

关于android - 如何在android中显示DialogFragment android.support.v4.app.DialogFragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23539735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com