Reputation: 145
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();
Upvotes: 8
Views: 5228
Reputation: 4644
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>
Upvotes: 6
Reputation: 1236
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);
Upvotes: 1
Reputation: 1092
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();
Upvotes: 8
Reputation: 3171
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.
Upvotes: -2
Reputation: 1795
I think it will works For You. https://github.com/drakeet/MaterialDialog
Upvotes: -1
Reputation: 9
Use <item name="android:textAllCaps">false</item>
in the definition of your application theme. Then all dialogs in the application are no more uppercase.
Upvotes: -4