我的Dialog.Builder
有一个问题,其中的按钮已被切断。
如何解决此问题,或者这是Motorola设备的问题?
设备:摩托罗拉Moto G /操作系统:Android 5.0.2
设备: Galaxy S5 /操作系统:Android 5.0.2
这是用于显示对话框的代码和主题
public void showDialog(final String title, final String message,
final OnClickListener onClickPositive,
final OnClickListener onCLickNegative, final String positiveButton,
final String negativeButton, final boolean cancelable) {
if (!isFinishing()) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (dialog != null && dialog.isShowing()) {
dialog.cancel();
}
Builder builder;
if (android.os.Build.VERSION.SDK_INT >= 14) {
builder = new AlertDialog.Builder(new ContextThemeWrapper(
MyActivity.this,
android.R.style.Theme_DeviceDefault_Light_Dialog));
} else {
builder = new Builder(MyActivity.this);
}
if (title != null) {
builder.setTitle(title);
}
if (message != null) {
builder.setMessage(message);
}
if (positiveButton != null) {
builder.setPositiveButton(positiveButton, onClickPositive);
}
if (negativeButton != null) {
builder.setNegativeButton(negativeButton, onCLickNegative);
}
builder.setCancelable(cancelable);
dialog = builder.show();
colorizeDialog(dialog);
}
});
}
}
//theme-xml
<style name="Theme.DeviceDefault.Light.Dialog" parent="Theme.Holo.Light.Dialog" >
<item name="android:windowTitleStyle">@android:style/DialogWindowTitle.DeviceDefault.Light</item>
<item name="android:windowAnimationStyle">@android:style/Animation.DeviceDefault.Dialog</item>
<item name="android:buttonBarStyle">@android:style/DeviceDefault.Light.ButtonBar.AlertDialog</item>
<item name="borderlessButtonStyle">@android:style/Widget.DeviceDefault.Light.Button.Borderless.Small</item>
<item name="textAppearance">@android:style/TextAppearance.DeviceDefault.Light</item>
<item name="textAppearanceInverse">@android:style/TextAppearance.DeviceDefault.Light.Inverse</item>
</style>
更新编辑
似乎,每个设备上的行为都不相同。我们还有第二个问题,添加了“中性”按钮。同样, Galaxy S5 在彼此下方添加按钮(从上到下:positiv,neutral,negative)
摩托罗拉Moto G (API 5.0.2/左侧)在中间显示红色按钮(红色“Abbrechen”),并再次剪切按钮文本(蓝色箭头)。
Nexus 4 (API 4.3/右侧)在左侧而非中间显示中性按钮
好像我们必须实现自定义对话框...。
最佳答案
您是否尝试过使用Dialog?
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.custom);
dialog.setTitle("Title...");
// set the custom dialog components - text, image and button
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("Android custom dialog example!");
// make 3 buttons instead of one
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//do something
}
});
dialog.show();
建议:对对话框使用线性布局。