gpt4 book ai didi

Android 5.x : Why does Dialog. Builder 切断文本?

转载 作者:IT王子 更新时间:2023-10-28 23:26:38 26 4
gpt4 key购买 nike

我对 Dialog.Builder 有疑问,其中的按钮被切断。我该如何解决这个问题,或者这是摩托罗拉设备的问题?

  • 缩短文本不是解决办法
  • 我希望与 S5 屏幕截图相同的行为,按钮太长 -> 按钮在彼此下方

设备:摩托罗拉 Moto G/操作系统:Android 5.0.2 enter image description here

设备:Galaxy S5/操作系统:Android 5.0.2 enter image description here

这是显示对话框的代码和主题

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在彼此下方添加按钮(从上到下:正、中性、负)

enter image description here

Motorola 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();

建议:对对话框使用线性布局。

关于Android 5.x : Why does Dialog. Builder 切断文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31512175/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com