我正在尝试实现一个由服务触发的警报对话框(在异步线程中)。所以我决定通过一个 Activity (ShowAlert.class)来实现警报对话框。当使用我的后台服务触发对话框时,它在后台显示我的默认布局。即使我没有在警报 Activity (ShowAlert.class)中设置任何布局。谁能帮我,如何从背景中删除默认布局。
注意:我对自定义布局不感兴趣。
代码:
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/