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

前端 未结 6 1523
自闭症患者
自闭症患者 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:13

    use following code, let buttons on the right and vertical arrangement

    alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                try {
                    LinearLayout linearLayout = (LinearLayout) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).getParent();
                    if (linearLayout != null) {
                        linearLayout.setOrientation(LinearLayout.VERTICAL);
                        linearLayout.setGravity(Gravity.RIGHT);
                    }
                } catch (Exception ignored) {
    
                }
            }
        });
    

提交回复
热议问题