我有一个我显示的警报,但无论我做什么,alertdialog显示一个空白的标题和消息.图标,正面按钮和负面按钮显示正确的描述.以下是我使用的代码片段:在Manifest文件中:
<uses-sdk
android:minSdkVersion="5"
android:targetSdkVersion="16" />
Run Code Online (Sandbox Code Playgroud)
在我的代码中,我声明:
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
Run Code Online (Sandbox Code Playgroud)
我还声明了上下文:
final Context context = this;
Run Code Online (Sandbox Code Playgroud)
我发出警报:
public void confirm() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
// set title
alertDialogBuilder.setTitle("This is title");
alertDialogBuilder.setIcon(R.drawable.ic_delete);
// set dialog message
alertDialogBuilder
.setMessage("This is the message")
.setCancelable(false)
.setPositiveButton(R.string.yes,new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, close
// current activity
MainActivity.this.finish();
}
})
.setNegativeButton(R.string.no,new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button …Run Code Online (Sandbox Code Playgroud)