我已经显示AlertDialog
有2个按钮,即是和取消,这是代码。
final AlertDialog.Builder builder = new AlertDialog.Builder(RiderDetailActivity.this);
builder.setCancelable(false);
builder.setMessage("Are you sure?");
final AlertDialog dialog = builder.create();
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialog.dismiss();
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialog.dismiss();
}
});
dialog.show();
这不会在三星Galaxy s4上显示是和取消按钮
但是当我与dialog.setButton
一起使用时,它可以很好地运作
dialog.setButton(DialogInterface.BUTTON_POSITIVE, "Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialog.dismiss();
}
});
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialog.dismiss();
}
});
注意: builder.setPositiveButton
和builder.setNegativeButton
仅在三星Galaxy S4上造成问题,对于其他正常运行的设备而言。
我需要在为构建器设置按钮后创建对话框,但我关心的是为什么它与其他设备一起工作而只是用Samsung Galaxy S4创建问题?
答案 0 :(得分:4)
试试这种方式。我希望这对你有用。
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(false);
builder.setMessage("Are you sure?");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
final AlertDialog dialog = builder.create();
dialog.show();
答案 1 :(得分:2)
在alertDialog.show()
方法后添加这两行
alertDialog.getButton(alertDialog.BUTTON_NEGATIVE).setTextColor(ContextCompat.getColor(_context, R.color.red));
alertDialog.getButton(alertDialog.BUTTON_POSITIVE).setTextColor(ContextCompat.getColor(_context, R.color.red));
答案 2 :(得分:1)
在添加按钮之前,您正在创建对话框。
移动
bool Image::operator >> (string filename) {
ofstream file;
file.open(filename,ios::out | ios::binary);
if (!file) {
cerr << "Cannot open file" << endl;
return false;
}
file << "P6" <<"\n";
file << getWidth() << "\n";
file << getHeight() << "\n";
file << "255" << "\n";
size_t size = height * width;
void*img = getRawDataPtr(); //returns void* buffer
unsigned char * temp = new unsigned char[size*3];
Vec3<float>* buff = (Vec3<float>*)img;
for (int i = 0; i<size; i++) {
Vec3<float> vector;
vector[0] =buff[i].x;
vector[1] = buff[i].y;
vector[2] = buff[i].z; // /255.f;
buff[i] = vector;
}
for (int i = 0; i < size; i++) {
temp[i * 3] = static_cast<unsigned char>(buff[i].x);
temp[i * 3 + 1] = static_cast<unsigned char>(buff[i].y);
temp[i * 3 + 2] = static_cast<unsigned char>(buff[i].z);
}
file.write((char *)temp, size * 3);
if (file.fail()) {
cerr << "Could not write data" << endl;
return false;
}
file.clear();
file.close();
return true;
delete[] buff;
delete[] temp;
}
设置按钮后
答案 3 :(得分:0)
您可以尝试使用此代码..
new AlertDialog.Builder(this)
.setTitle("Add new Title")
.setMessage("Type Message here")
.setPositiveButton("Add", (dialog, whichButton) -> {
// Onclick event Here
})
.setNegativeButton("Close",(dialog, i) -> {
})
.show();