Я создал собственный диалог, чтобы создать один стандартный диалог, который я мог бы создать всего одной строкой позже, и он был бы стандартным. С параметрами меняю текст. Диалог очень упрощен и имеет только одну кнопку.
Теперь я переосмысливаю, что это была хорошая идея. Я действительно хочу, чтобы мое приложение остановилось, пока не отобразится мой диалог. Как я мог это сделать? Дать диалогу возвращаемый тип? Или есть лучший способ?
мой диалог:
/**
* custom dialog
*
* @param mcontext use activityname.this
* @param title
* @param text
* @param button
*/
public void showDialog(Context mcontext, String title,String text, String button) {
// fonts
Typeface tf_hn = Typeface.createFromAsset(mcontext.getAssets(), "helveticaneue.ttf");
Typeface tf_hn_bold = Typeface.createFromAsset(mcontext.getAssets(), "helveticaneuebd.ttf");
Resources res = mcontext.getResources();
// custom dialog
final Dialog dialog = new Dialog(mcontext);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); //not the normal dialog title
dialog.setContentView(R.layout.view_dialog);
TextView tv_dialog_title = (TextView) dialog.findViewById(R.id.tv_dialog_title);
tv_dialog_title.setText(title);
tv_dialog_title.setTypeface(tf_hn_bold);
tv_dialog_title.setTextColor(res.getColor(R.color.white));
TextView tv_dialog_text = (TextView) dialog.findViewById(R.id.tv_dialog_text);
tv_dialog_text.setText(text);
tv_dialog_text.setTypeface(tf_hn);
tv_dialog_text.setTextColor(res.getColor(R.color.white));
Button dialogButton = (Button) dialog.findViewById(R.id.bt_dialog_button);
dialogButton.setTypeface(tf_hn_bold);
dialogButton.setText(button);
dialogButton.setTextColor(res.getColor(R.color.white));
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
и тогда я могу использовать его так:
dialogH.showDialog(LoginActivity.this, res.getString(R.string.txt_dialog_fout), res.getString(R.string.txt_dialog_not_connected),res.getString(R.string.txt_dialog_button));
Все работало нормально, пока я не захотел показать диалоговое окно с надписью «Вы вошли в систему» (или около того), а затем запустить намерение после того, как дисплей был отключен. У кого-нибудь есть идея?