为什么应用中没有显示正负按钮? 你们有什么想法要改变吗?感谢。
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
vibrator.vibrate(100);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Berühre mich noch einmal und du wirst's bereuen!!");
builder.setPositiveButton("OK sorry", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "Sorry Herr Gauß! ", Toast.LENGTH_LONG).show();
}
});
builder.setNegativeButton("Mir egal.", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "Mehr als vibrieren kannst du eh nicht!", Toast.LENGTH_LONG).show();
}
});
builder.create().show();
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MainActivity.this, R.style.MyDialogTheme);
}
}
答案 0 :(得分:0)
删除创建新对话框的最后一行,再次在创建对话框上设置主题
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
vibrator.vibrate(100);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this, R.style.MyDialogTheme);
builder.setTitle("Berühre mich noch einmal und du wirst's bereuen!!");
builder.setPositiveButton("OK sorry", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "Sorry Herr Gauß! ", Toast.LENGTH_LONG).show();
}
});
builder.setNegativeButton("Mir egal.", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "Mehr als vibrieren kannst du eh nicht!", Toast.LENGTH_LONG).show();
}
});
builder.create().show();
}
}
答案 1 :(得分:0)
试试这个:
new AlertDialog.Builder(MainActivity.this)
.setPositiveButton("OK sorry", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which)
{
Toast.makeText(MainActivity.this, "Sorry Herr Gauß! ", Toast.LENGTH_LONG).show();
}
})
.setNegativeButton("No", null)
.setTitle("Berühre mich noch einmal und du wirst's bereuen!!")
.setMessage("Hello world")
.show();