gpt4 book ai didi

java - 找不到适合 show(ActionBar,String) 方法的方法 DialogFragment.show(FragmentTransaction,String) 不适用

转载 作者:行者123 更新时间:2023-12-01 11:36:46 25 4
gpt4 key购买 nike

获取

Error:(192, 23) error: no suitable method found for show(ActionBar,String)
method DialogFragment.show(FragmentTransaction,String) is not applicable
(actual argument ActionBar cannot be converted to FragmentTransaction by method invocation conversion)
method DialogFragment.show(FragmentManager,String) is not applicable
(actual argument ActionBar cannot be converted to FragmentManager by method invocation conversion)

尝试创建自定义对话框时,在 dialog.show(getSupportActionBar(), "dialog"); 这段代码中出现错误。

这是我的简短代码:

public boolean onPrepareOptionsMenu(android.view.Menu menu) {
// if nav drawer is opened, hide the action items
boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
Button settBtn = (Button) findViewById(R.id.action_settings);
settBtn.setOnClickListener(new View.OnClickListener() {
@SuppressWarnings("deprecation")
public void onClick(View v) {
CustomDialogFragment dialog = new CustomDialogFragment();
dialog.show(getSupportActionBar(), "dialog");

}
});
return super.onPrepareOptionsMenu(menu);
}

public class CustomDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = new Dialog(getActivity());
dialog.getWindow().getAttributes().windowAnimations = R.style.Animation_CustomDialog;
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
dialog.setContentView(R.layout.dialog_custom);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.setCanceledOnTouchOutside(false);
TextView message = (TextView) dialog.findViewById(R.id.message);
message.setText(">>>>>>>");
dialog.findViewById(R.id.positive_button).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dismiss();
}
});

dialog.findViewById(R.id.close_button).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dismiss();
}
});
return dialog;
}
}

请帮我解决这个问题。提前致谢......

最佳答案

使用FragmentManager解决

FragmentManager fm;
fm= getFragmentManager();
CustomDialogFragment dialog = new CustomDialogFragment();
dialog.show(fm , "dialog");

关于java - 找不到适合 show(ActionBar,String) 方法的方法 DialogFragment.show(FragmentTransaction,String) 不适用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29893557/

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