android - 没有布局的对话框 Activity

标签 android android-layout android-alertdialog

我正在尝试实现一个由服务触发的警报对话框(在异步线程中)。所以我决定通过一个 Activity (ShowAlert.class)来实现警报对话框。当使用我的后台服务触发对话框时,它在后台显示我的默认布局。即使我没有在警报 Activity (ShowAlert.class)中设置任何布局。谁能帮我,如何从背景中删除默认布局。

注意:我对自定义布局不感兴趣。

enter image description here

代码:

public class ShowAlert extends Activity
{
AlertDialog alertDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage("message");
alertDialogBuilder.setTitle("Title");
alertDialogBuilder.setCancelable(true);
alertDialogBuilder.setPositiveButton("OK", 
new DialogInterface.OnClickListener() {

   @Override
   public void onClick(DialogInterface arg0, int arg1) {
      Intent positveActivity = new Intent(getApplicationContext(),HomeMap.class);
      // Sets the Activity to start in a new, empty task
      positveActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      positveActivity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      startActivity(positveActivity);

   }
});
alertDialogBuilder.setNegativeButton("Cancel", 
new DialogInterface.OnClickListener() {

   @Override
   public void onClick(DialogInterface dialog, int which) {
       alertDialog.cancel();
     }
});

alertDialog = alertDialogBuilder.create();
alertDialog.show();
}

}

最佳答案

创建 Activity

public class AlertActivity extends Activity {

    TextView dialog_title;
    TextView dialog_message;

    @Override
    protected void onCreate (Bundle savedInstanceState) {

        super.onCreate (savedInstanceState);

        this.requestWindowFeature (Window.FEATURE_NO_TITLE);
        getWindow ().setBackgroundDrawableResource (android.R.color.transparent);
        setContentView (R.layout.view_custom_alert);

        dialog_title = (TextView) findViewById (R.id.dialog_title);
        dialog_message = (TextView) findViewById (R.id.dialog_message);

        dialog_title.setText ("Alert!");
        dialog_message.setText ("Reminder text here....                                                   ");
    }
}

在您的 list 中

<activity
        android:name="com.telmate.custom.AlertActivity"
        android:excludeFromRecents="true"
        android:launchMode="singleInstance"
        android:taskAffinity=""
        android:theme="@android:style/Theme.Dialog" />

关于android - 没有布局的对话框 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26967127/

相关文章:

java - 从 Json 数据获取图像并将其显示为 RecyclerView android 中的封面图像

android - 在 Firebase 中保存数据后 Activity 重启

android - 混帐 : How to Push missing branches from one repo to another repo

android - 在布局内的运行时多次膨胀一个布局

android - textInputLayout 的右侧边框在 alertdialog 中被裁剪

android - 如何在按钮上设置位图?

android - 通过 XML 将选项卡添加到操作栏

android-layout - 为什么我的 Android setOnItemClickListener 不起作用?

android - 警报对话框准备

android - 如何在android中使用自定义单选按钮在警报对话框上添加监听器