Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 本地化应用程序会使对话看起来太小_Java_Android_Locale - Fatal编程技术网

Java 本地化应用程序会使对话看起来太小

Java 本地化应用程序会使对话看起来太小,java,android,locale,Java,Android,Locale,翻译完我的应用程序后,我让用户可以更改他们的语言环境。这样做会使我显示的对话看起来太小。为什么?我怎样才能修好它 本地化代码: Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; getBaseContext().getResources().updateConfiguration(config, getBa

翻译完我的应用程序后,我让用户可以更改他们的语言环境。这样做会使我显示的对话看起来太小。为什么?我怎样才能修好它

本地化代码:

    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());

如果我将其删除,对话将恢复正常,但应用程序未本地化…

您是否尝试从代码中删除getDisplayMetrics()?由于本地化资源只是用getResources更新的,所以我应该怎么做?getBaseContext().getResources().updateConfiguration(配置,getBaseContext().getResources());不编译。。。如果我删除了整个getBaseContext,应用程序将无法正确翻译。我的问题是,也许你可以在他们获取上下文配置的地方尝试这个答案,更改区域设置并更新它。有一个答案确实有用——Gmari21的答案。