android 获取当前语言环境language来改变UI

有时候,界面在不同的语言环境下面显示的UI会出现不和谐的情况.所以在代码中会用区分语言环境的办法来做.

比如如下这段代码,判断了如果当前是英文环境,则对textview控件做布局的修改:

if(null!=centerTitle){
        	Configuration conf = getResources().getConfiguration();
            String locale = conf.locale.getDisplayName(conf.locale);
            if (locale != null && locale.length() > 1) 
            {
                locale = Character.toUpperCase(locale.charAt(0)) + locale.substring(1);
                if(locale.startsWith("English")){
                	RelativeLayout.LayoutParams rLayoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT) ;
                	rLayoutParams.addRule(RelativeLayout.RIGHT_OF,R.id.application_bar_leftButton) ;
                	rLayoutParams.addRule(RelativeLayout.CENTER_VERTICAL) ;
                	centerTitle.setLayoutParams(rLayoutParams) ;
                }
            }
        }
 

猜你喜欢

转载自pop1030123.iteye.com/blog/1666786