Dialog buttons with long text not wrapping / squeezed out - material theme on android 5.0 lollipop

前端 未结 6 1417
自闭症患者
自闭症患者 2021-02-01 14:37

While optimizing an app for material theme on lollipop, I\'m encountering this annoying problem:

Whenever there is long text on dialog buttons, that doesn\'t fit the but

6条回答
  •  佛祖请我去吃肉
    2021-02-01 15:17

    This could be fixed with using stacked buttons instead of row buttons. Here my workaround how it could be achieved with using AppCompat lib :

    Code import android.support.v7.app.AlertDialog;

        AlertDialog.Builder builder;
        builder = new AlertDialog.Builder(context, R.style.StackedAlertDialogStyle);
        builder.setTitle("Title");
        builder.setMessage("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc dignissim purus eget gravida mollis. Integer in auctor turpis. Morbi auctor, diam eget vestibulum congue, quam arcu pulvinar dui, blandit egestas erat enim non ligula." +
                " Nunc quis laoreet libero. Aliquam consectetur nibh eu arcu eleifend efficitur.");
        builder.setPositiveButton("Positive Button", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
            }
        });
        builder.setNeutralButton("Neutral Button", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
            }
        });
        builder.setNegativeButton("Cancel Button", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
            }
        });
        AlertDialog alertDialog = builder.create();
        alertDialog.show();
            try{
                final Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
                LinearLayout linearLayout = (LinearLayout) button.getParent();
                linearLayout.setOrientation(LinearLayout.VERTICAL);
            } catch(Exception ex){
                //ignore it
            }
    

    Style

    
    
    
    

    Result

    Stacked Alert Dialog

提交回复
热议问题