2015-07-20 32 views
17

Tôi gặp sự cố với số Dialog.Builder, trong đó các Nút bị cắt. Làm cách nào để giải quyết vấn đề này hoặc đây có phải là sự cố cho thiết bị Motorola không?Android 5.x: Tại sao Dialog.Builder cắt văn bản?

  • làm cho văn bản ngắn không phải là một giải pháp
  • tôi hy vọng các hành vi tương tự như S5-chụp màn hình, nút quá lâu -> Buttons bên dưới mỗi khác

Device: Motorola Moto G/Hệ điều hành: Android 5.0.2 enter image description here

Device: Galaxy S5/Hệ điều hành: Android 5.0.2 enter image description here

Đây là mã và chủ đề cho hiển thị Dialog

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> 

########################

CẬP NHẬT EDIT

có vẻ như, hành vi này là không giống nhau trên mọi thiết bị. Chúng tôi gặp vấn đề thứ hai, với việc thêm nút "trung lập". Một lần nữa, Galaxy S5 thêm nút bên dưới mỗi khác (từ trên xuống dưới: positiv, trung lập, tiêu cực)

enter image description here

Motorola Moto G (API 5.0.2 bên/trái) cho thấy nút trung lập trong giữa (màu đỏ "Abbrechen") và cắt một lần nữa các văn bản nút (mũi tên màu xanh).

Nexus 4 (API 4.3 bên/phải) cho thấy các nút trung lập ở phía bên trái, thay vì ở giữa

Có vẻ như chúng ta phải thực hiện một hộp thoại tùy chỉnh ....

+0

Tôi nghĩ rằng vấn đề là độ dài văn bản vượt quá độ dài cửa sổ. Bạn không thể đặt văn bản dài hơn kích thước vùng chứa đó. – Giuseppe

+0

@Giuseppe: Có, văn bản quá dài. Vấn đề là, tại sao Galaxy S5 xử lý quyền này (Các nút được hiển thị bên dưới lẫn nhau), trong khi hành vi mong đợi này không hoạt động trên Motorola ?! – longilong

+0

ah ok, bạn không chỉ định điều này. Tôi nghĩ đó là giải pháp thay thế của bạn để giải quyết vấn đề này. Có lẽ vấn đề là trên người nghe của bạn và máy xây dựng mã sai! OnClickPositive và onClickNegative là gì? – Giuseppe

Trả lời

0

Bạn đã thử sử dụng Dialog thay thế chưa?

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

đề xuất: sử dụng bố cục tuyến tính cho hộp thoại.

Các vấn đề liên quan