大家好我有一个我创建的自定义警报对话框。在构建器中我将cancelable设置为false但是当我按下后退按钮时它仍然消失了吗?
这是对话框的代码:
public final class HemisphereDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View customTitle = inflater.inflate(R.layout.hemisphere_dialog_custom_title, null);
builder.setCustomTitle(customTitle);
String[] entries = new String[2];
entries[0] = getResources().getString(R.string.northern_hemisphere);
entries[1] = getResources().getString(R.string.southern_hemisphere);
builder.setItems(entries, new DialogInterface.OnClickListener() {
//The 'which' argument contains the index position of the selected item
public void onClick(DialogInterface dialog, int which) {
if( which == 0 ) {
GlobalVariables.getShared().setIsInNorthernHemisphere(true);
} else if( which == 1 ) {
GlobalVariables.getShared().setIsInNorthernHemisphere(false);
}
ToolbarActivity.outfitsFragment.hemisphereSelected();
GlobalVariables.getShared().setHasAskedForHemisphere(true);
}
});
builder.setCancelable(false);
//Create the AlertDialog object and return it
return builder.create();
}
这就是它的显示方式:
new HemisphereDialogFragment().show(getSupportFragmentManager(), "hemisphereDialog");
另一个小问题,是否有办法更改对话框中项目的文字大小?
答案 0 :(得分:2)
您将警报对话框设置为false,但您的片段仍设置为可取消,您还需要将<?php
$str = "cricket, foot ball, hockey, basket ball";
$games = (explode(",",$str));
for($i=0; $i<count($games); $i++){
$game = trim($games[$i]," ");
$game = str_replace(' ', '-', $game);
echo '<a href="/game.php='.$game.'">'.$games[$i].'</a><br>';
}
?>
添加到您的片段中。
答案 1 :(得分:1)
你应该在Dialog片段本身而不是AlertDialog.Builder中调用setCancellable(false)。