Using Locale to force Android to use a specific strings.xml file for a non-supported language

前端 未结 4 1015
甜味超标
甜味超标 2020-12-06 06:00

...and if so, how?

We make a dedicated Android device for use in an industrial environment. It\'s basically a tablet, but with only one app running. The user is n

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-06 06:23

    Override getResources in Application and BaseActivity

    @Override
        public Resources getResources() {
            if(mRes == null)
            mRes = new PowerfulResources(getAssets(),new DisplayMetrics(), null);
            return mRes;
        }
    
        public static class PowerfulResources extends Resources{
    
            /**
             * Create a new Resources object on top of an existing set of assets in an
             * AssetManager.
             *
             * @param assets  Previously created AssetManager.
             * @param metrics Current display metrics to consider when
             *                selecting/computing resource values.
             * @param config  Desired device configuration to consider when
             */
            public PowerfulResources(AssetManager assets, DisplayMetrics metrics, Configuration config) {
                super(assets, metrics, config);
            }
    
            @NonNull
            @Override
            public String getString(int id) throws NotFoundException {
                //do your stuff here
                return super.getString(id);
            }
        }
    

    also read this

提交回复
热议问题