After I translated my app, I made it possible for users to change their locale. Doing so made dialogues I show look too small. Why? How can I fix it?
Code for localizing:
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
Code for showing a dialog:
final Dialog dialog = new Dialog(mContext);
dialog.setTitle(context.getResources().getString(R.string.rate) + APP_TITLE + "!");
LinearLayout ll = new LinearLayout(mContext);
ll.setOrientation(LinearLayout.VERTICAL);
TextView tv = new TextView(mContext);
tv.setText(context.getResources().getString(R.string.if_you_enjoy_using)
+ APP_TITLE
+ context.getResources().getString(
R.string.please_take_a_moment_to_rate_it_thanks_for_your_support));
tv.setWidth(240);
tv.setPadding(4, 0, 4, 10);
if (Locale.getDefault().getLanguage().equals("ja"))
{
tv.setTextSize(13);
}
ll.addView(tv);
Button b1 = new Button(mContext);
b1.setText(context.getResources().getString(R.string.rate) + APP_TITLE);
b1.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
<code>
}
});
ll.addView(b1);
Button b2 = new Button(mContext);
b2.setText(R.string.remind_me_later);
b2.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
<code>
}
});
ll.addView(b2);
Button b3 = new Button(mContext);
b3.setText(R.string.no_thanks);
b3.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
<code>
}
});
ll.addView(b3);
dialog.setContentView(ll);
dialog.show();
The dialogues: Before:
After:
After debugging the problem is with this:
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
If I drop it, the dialogues return to normal, but the app is not localized...