修改设置语言选项,删除 [Developer]Accented English或者增加其他自己喜欢的语种

经常会遇见下面的情况,表示很烦躁


语言选项里面多了第一个[Developer] Accented English 看到它就不爽,怎么删除呢?

在进入到系统设置-语言和输入法-语言,界面就会出现一列语言清单,有各种各样的语言,点击某一个语言后系统就会被设置成该语言环境。那么,这列语言的字符串资源是从哪里获取到的呢?现在结合自己的理解介绍如下:
首先,从Settings的xml目录下settings_headers.xml文件中可以知道“语言和输入法”的选项在InputMethodAndLanguageSettings.java类中,如图:![settings_headers.xml中的部分设置项][1]

然后从InputMethodAndLanguageSettings类中的onCreate()方法知道“语言和输入法”的设置布局文件为language_settings.xml文件下:![InputMethodAndLanguageSettings.java部分代码][2]
接着,我们再找到language_settings.xml布局文件:![language_settings布局文件部分代码][3]
可知,"语言"这一选项的代码实现是在LocalePicker.java下,接着再找到LocalePicker类:![LocalePicker类代码][4]
从代码可知,改类继承自framework层下的一个同名LocalePicker类,该类只是作为一个接口,具体实现是在com.android.internal.app.LocalePicker文件中,截取关键代码:

public static ArrayAdapter<LocaleInfo> constructAdapter(Context conte...

它里面可以找到

 else {
                        String displayName;
                        if (s.equals("zz_ZZ")) {
                            displayName = " [Developer] Accented English";
                        }  else {
                            displayName = toTitleCase(l.getDisplayLanguage(l));
                        }
                        if (DEBUG) {
                            Log.v(TAG, "adding "+displayName);
                        }
                       preprocess[finalSize++] = new LocaleInfo(displayName, l);
                    }
以上的代码,显然是把
" [Developer] Accented English" 
赋值给了displayName ,然后把它加入到数组preprocess[]里面去,可以获得所加的数组大小其实就是finalSize的值,然后有下面的代码:

        final LocaleInfo[] localeInfos = new LocaleInfo[finalSize -1];
        for (int i = 0; i < finalSize -1; i++) {
            localeInfos[i] = preprocess[i];
			Log.d("pishum","" + preprocess[i]);
        }

把数组preprocess []放到localeInfos[]数组里面去,由于我打了log,显示的我要去掉的Developer Accented English是在数组的最后一个元素位置,所以我上面的代码是我修改过的,只需要将preprocess[]数组除了最后一个元素全部赋值到数组localeInfos[]就可以了,那个Developer Accented English 的选项自然就会北删除掉

这段代码是一个用于编码转换的示例,它展示了如何使用Python来实现将Unicode数据编码为XML和HTML实体的功能。 让我们逐句解释一下代码: ```python import codecs from htmlentitydefs import codepoint2name ``` 首先,导入了codecs库和codepoint2name模块,后者包含了HTML实体的名称和对应的Unicode码点。 ```python def encode_for_xml(unicode_data, encoding='ascii'): return unicode_data.encode(encoding, 'xmlcharrefreplace') ``` 这是一个名为encode_for_xml的函数,它接受一个Unicode字符串和一个可选的编码参数。它使用给定的编码对Unicode数据进行编码,并将无法编码的字符替换为XML字符引用。 ```python def html_replace(exc): if isinstance(exc, (UnicodeEncodeError, UnicodeTranslateError)): s = [u'&%s;' % codepoint2name[ord(c)] for c in exc.object[exc.start:exc.end]] return ''.join(s), exc.end else: raise TypeError("can't handle %s" % exc.__name__) codecs.register_error('html_replace', html_replace) ``` 这是一个名为html_replace的函数,它是一个错误处理函数。当遇到无法编码的字符时,将调用此函数来处理。它将无法编码的字符替换为对应的HTML实体。 ```python def encode_for_html(unicode_data, encoding='ascii'): return unicode_data.encode(encoding, 'html_replace') ``` 这是另一个编码函数,名为encode_for_html。它与encode_for_xml函数类似,但是使用html_replace函数来处理无法编码的字符。 ```python if __name__ == '__main__': unicode_data = u'\N{LATIN SMALL LETTER A WITH DIAERESIS}' print encode_for_xml(unicode_data, encoding='ascii') data = u''' <html> <head> <title>Encoding Test</title> </head> <body> <p>accented characters: <ur> <li>\xe0 (a + grave) <li>\xe7 (c + cedilla) <li>\xe9 (a + acute) </ul> <p>symbols: <ul> <li>\xa3 (British pound) <li>\u20ac (Euro) <li>\u221e (infinity) </ul> </body></html> ''' print encode_for_xml(data) print encode_for_html(data) ``` 在这个if __name__ == '__main__'的块中,我们定义了一些测试数据并调用了encode_for_xml和encode_for_html函数来进行编码转换。输出将会显示Unicode数据的编码结果。 至于html_replace(exc)函数的参数例子,你可以将其添加到代码中并进行测试。例如: ```python def html_replace(exc): if isinstance(exc, (UnicodeEncodeError, UnicodeTranslateError)): s = [u'&%s;' % codepoint2name[ord(c)] for c in exc.object[exc.start:exc.end]] return ''.join(s), exc.end elif isinstance(exc, UnicodeDecodeError): # 示例参数例子 return u'&%s;' % codepoint2name[ord(exc.object[exc.start])], exc.end else: raise TypeError("can't handle %s" % exc.__name__) ``` 这样,当遇到Unicode解码错误时,将替换为对应的HTML实体。你可以在测试数据中添加一些无法解码的字符来进行测试。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值