在我翻译我的应用后,我让用户可以更改他们的语言环境。这样做了我展示的对话看起来太小了。为什么?我该如何解决?
本地化代码:
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
显示对话框的代码:
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();
对话: 之前:
后:
调试后问题出现了:
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
如果我放弃它,对话会恢复正常,但应用程序未本地化...