Alert dialog buttons problems in Android L

一世执手 提交于 2020-01-02 03:11:10

问题


I have created a AlertDialog in my app. Before Android L AlertDialog buttons fit in dialog box, but in Android L buttons label automatically converts in title case and buttons not fit in dialog box. Please see screenshots:

Android L:

Android Kitkat:

Is anybody see this issue. Can any help me to solve this problem, although this is latest android version.

Code: (I have not used xml code to create dialog, here is java code:)

AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setTitle(R.string.feedback_label);
        alert.setMessage(msgStrId);
        alert.setNegativeButton(R.string.close_label, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
            }
        });
        alert.setPositiveButton(R.string.rate_app, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
            }
        });
        alert.setNeutralButton(R.string.feedback_label,new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) 
            {
                // TODO Auto-generated method stub
            }
        });
        alert.setOnCancelListener(new DialogInterface.OnCancelListener() 
        {
            @Override
            public void onCancel(DialogInterface dialog) 
            {
                // TODO Auto-generated method stub
            }
        });
        AlertDialog alertDialog = alert.create();
        alertDialog.show();

回答1:


I know, I am too late. But I share my suggestion here. Maybe it will be helpful.

  AlertDialog alertDialog  = alert.create();
    alertDialog .show();
    alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setAllCaps(false);
    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setAllCaps(false);
    alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL).setAllCaps(false);
 alertDialog.show();



回答2:


I think it will works For You. https://github.com/drakeet/MaterialDialog




回答3:


A slight modification to @Kush's answer. You don't have to call dialog.show() multiple times.

AlertDialog.Builder builder = new AlertDialog.Builder(MyActivity.this);
        builder.setTitle("Title");
        builder.setMessage("message");
        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //Do Something
            }
        });
        AlertDialog dialog = builder.create();
        dialog.show();
       dialog.getButton(AlertDialog.BUTTON_POSITIVE).setAllCaps(false);



回答4:


    AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.MyAlertDialogStyle);

styles.xml

<style name="MyAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog">
    <item name="android:textAllCaps">false</item>
</style>



回答5:


If you will try to find solution for this then you might get but also for small screens you will stuck again and you need to find something for it also.

So better is divide your string so it will resolve your issue for any screen.

For that follow below code.

Go to strings.xml file. and change your title as below.

 <string name="rate_app">Rate This \n App</string>
 <string name="feedback_label">Report \n Issues</string>

If "\n" not work then user
tag. Hope this will help you.




回答6:


Use <item name="android:textAllCaps">false</item> in the definition of your application theme. Then all dialogs in the application are no more uppercase.



来源:https://stackoverflow.com/questions/26708976/alert-dialog-buttons-problems-in-android-l

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!