Browser设置搜索引擎,在com.android.browser.preferences.GeneralPreferencesFragment中加载R.xml.general_preferences。
看看general_preferences.xml
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceCategory android:title="@string/pref_general_title"> <com.android.browser.preferences.NonformattingListPreference android:key="homepage_picker" android:entries="@array/pref_homepage_choices" android:entryValues="@array/pref_homepage_values" android:title="@string/pref_content_homepage" /> <com.android.browser.search.SearchEnginePreference android:defaultValue="@string/default_search_engine_value" android:dialogTitle="@string/pref_content_search_engine" android:key="search_engine" android:summary="@string/pref_content_search_engine_summary" android:title="@string/pref_content_search_engine" />
SearchEnginePreference来显示引擎列表,SearchEngines.getSearchEngineInfos(context)获取引擎
//SearchEngines获取引擎列表 public static List<SearchEngineInfo> getSearchEngineInfos(Context context) { ArrayList<SearchEngineInfo> searchEngineInfos = new ArrayList<SearchEngineInfo>(); String[] searchEngines = context.getResources().getStringArray(R.array.search_engines); for (int i = 0; i < searchEngines.length; i++) { String name = searchEngines[i]; SearchEngineInfo info = new SearchEngineInfo(context, name); searchEngineInfos.add(info); } return searchEngineInfos; }
Browser中所有的引擎列表在values/all_search_engines.xml中配置。R.array.search_engines配置要显示的引擎。
all_search_engines.xml
<resources> <string-array name="DuckDuckGo" translatable="false"> <item>DuckDuckGo</item> <item>duckduckgo.com</item> <item>http://duckduckgo.com/favicon.ico</item> <item>https://duckduckgo.com/?q={searchTerms}</item> <item>UTF-8</item> <item></item> </string-array> <string-array name="yahoo_uk" translatable="false"> <item>Yahoo! UK & Ireland</item> <item>uk.yahoo.com</item> <item>http://uk.search.yahoo.com/favicon.ico</item> <item>http://uk.search.yahoo.com/search?ei={inputEncoding}&fr=crmas&p={searchTerms}</item> <item>UTF-8</item> <item>http://uk-sayt.ff.search.yahoo.com/gossip-uk-sayt?output=fxjson&command={searchTerms}</item> </string-array> <string-array name="yahoo_jp" translatable="false"> <item>Yahoo! JAPAN</item> <item>yahoo.co.jp</item> <item>http://search.yahoo.co.jp/favicon.ico</item> <item>http://search.yahoo.co.jp/search?ei={inputEncoding}&fr=crmas&p={searchTerms}</item> <item>UTF-8</item> <item></item> </string-array> <string-array name="rambler" translatable="false"> <item>Rambler</item> <item>rambler.ru</item> <item>http://www.rambler.ru/favicon.ico</item> <item>http://www.rambler.ru/srch?words={searchTerms}</item> <item>windows-1251</item> <item></item> </string-array> <string-array name="yahoo_br" translatable="false"> <item>Yahoo! Brasil</item> <item>br.yahoo.com</item> <item>http://br.search.yahoo.com/favicon.ico</item> <item>http://br.search.yahoo.com/search?ei={inputEncoding}&fr=crmas&p={searchTerms}</item> <item>UTF-8</item> <item>http://br-sayt.ff.search.yahoo.com/gossip-br-sayt?output=fxjson&command={searchTerms}</item> </string-array> <string-array name="bing_zh_HK" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=zh-HK&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="bing_el_GR" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=el-GR&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="bing_tr_TR" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=tr-TR&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="ask_uk" translatable="false"> <item>Ask Jeeves</item> <item>uk.ask.com</item> <item>http://uk.ask.com/favicon.ico</item> <item>http://uk.ask.com/web?q={searchTerms}</item> <item>UTF-8</item> <item>http://ss.uk.ask.com/query?q={searchTerms}&li=ff</item> </string-array> <string-array name="nate" translatable="false"> <item>네이트닷컴</item> <item>nate.com</item> <item>http://nate.search.empas.com/favicon.ico</item> <item>http://nate.search.empas.com/search/all.html?q={searchTerms}</item> <item>EUC-KR</item> <item></item> </string-array> <string-array name="uol" translatable="false"> <item>UOL Busca</item> <item>busca.uol.com.br</item> <item>http://busca.uol.com.br/favicon.ico</item> <item>http://busca.uol.com.br/www/index.html?q={searchTerms}</item> <item>ISO-8859-1</item> <item></item> </string-array> <string-array name="baidu_cn" translatable="false"> <item>百度</item> <item>baidu.com</item> <item>http://www.baidu.com/favicon.ico</item> <item>http://www.baidu.com/s?wd={searchTerms}</item> <item>GB2312</item> <item></item> </string-array> <string-array name="baidu" translatable="false"> <item>Baidu</item> <item>baidu.com</item> <item>http://www.baidu.com/favicon.ico</item> <item>http://www.baidu.com/s?wd={searchTerms}</item> <item>UTF-8</item> <item></item> </string-array> <string-array name="yahoo_ch" translatable="false"> <item>Yahoo! Suche</item> <item>ch.yahoo.com</item> <item>http://ch.search.yahoo.com/favicon.ico</item> <item>http://ch.search.yahoo.com/search?ei={inputEncoding}&fr=crmas&p={searchTerms}</item> <item>UTF-8</item> <item></item> </string-array> <string-array name="bing_nl_BE" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=nl-BE&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="yahoo_cn" translatable="false"> <item>中国雅虎</item> <item>cn.yahoo.com</item> <item>http://sg.search.yahoo.com/favicon.ico</item> <item>http://sg.search.yahoo.com/search?ei={inputEncoding}&fr=crmas&p={searchTerms}</item> <item>UTF-8</item> <item></item> </string-array> <string-array name="onet" translatable="false"> <item>Onet.pl</item> <item>onet.pl</item> <item>http://szukaj.onet.pl/favicon.ico</item> <item>http://szukaj.onet.pl/query.html?qt={searchTerms}</item> <item>ISO-8859-2</item> <item></item> </string-array> <string-array name="ask_es" translatable="false"> <item>Ask.com España</item> <item>es.ask.com</item> <item>http://es.ask.com/favicon.ico</item> <item>http://es.ask.com/web?q={searchTerms}</item> <item>UTF-8</item> <item>http://ss.es.ask.com/query?q={searchTerms}&li=ff</item> </string-array> <string-array name="bing_cs_CZ" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=cs-CZ&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="altavista_se" translatable="false"> <item>AltaVista</item> <item>se.altavista.com</item> <item>http://se.altavista.com/favicon.ico</item> <item>http://se.altavista.com/web/results?q={searchTerms}</item> <item>UTF-8</item> <item></item> </string-array> <string-array name="mail_ru" translatable="false"> <item>\@MAIL.RU</item> <item>mail.ru</item> <item>http://img.go.mail.ru/favicon.ico</item> <item>http://go.mail.ru/search?q={searchTerms}</item> <item>windows-1251</item> <item></item> </string-array> <string-array name="hispavista" translatable="false"> <item>hispavista</item> <item>hispavista.com</item> <item>http://buscar.hispavista.com/favicon.ico</item> <item>http://buscar.hispavista.com/?cadena={searchTerms}</item> <item>iso-8859-1</item> <item></item> </string-array> <string-array name="bing_zh_CN" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=zh-CN&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="google" translatable="false"> <item>Google</item> <item>google.com</item> <item>https://www.google.com/favicon.ico</item> <item>https://www.google.com/search?ie={inputEncoding}&source=android-browser&q={searchTerms}</item> <item>UTF-8</item> <item>https://www.google.com/complete/search?client=android&q={searchTerms}</item> </string-array> <string-array name="bing_en_NZ" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=en-NZ&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="bing_fr_BE" translatable="false"> <item>Bing</item> <item></item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=fr-BE&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="rednano" translatable="false"> <item>Rednano</item> <item>rednano.sg</item> <item>http://rednano.sg/favicon.ico</item> <item>http://rednano.sg/sfe/lwi.action?querystring={searchTerms}</item> <item>UTF-8</item> <item></item> </string-array> <string-array name="goo" translatable="false"> <item>goo</item> <item>search.goo.ne.jp</item> <item>http://goo.ne.jp/favicon.ico</item> <item>http://search.goo.ne.jp/web.jsp?MT={searchTerms}&IE={inputEncoding}</item> <item>UTF-8</item> <item></item> </string-array> <string-array name="sapo" translatable="false"> <item>SAPO</item> <item>sapo.pt</item> <item>http://imgs.sapo.pt/images/sapo.ico</item> <item>http://pesquisa.sapo.pt/?q={searchTerms}</item> <item>UTF-8</item> <item>http://pesquisa.sapo.pt/livesapo?q={searchTerms}</item> </string-array> <string-array name="bing_it_IT" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=it-IT&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="bing_es_ES" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=es-ES&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="abcsok" translatable="false"> <item>ABC Søk</item> <item>abcsok.no</item> <item>http://abcsok.no/favicon.ico</item> <item>http://abcsok.no/index.html?q={searchTerms}</item> <item>UTF-8</item> <item></item> </string-array> <string-array name="yahoo_dk" translatable="false"> <item>Yahoo! Danmark</item> <item>dk.yahoo.com</item> <item>http://dk.search.yahoo.com/favicon.ico</item> <item>http://dk.search.yahoo.com/search?ei={inputEncoding}&fr=crmas&p={searchTerms}</item> <item>UTF-8</item> <item></item> </string-array> <string-array name="yahoo_de" translatable="false"> <item>Yahoo! Deutschland</item> <item>de.yahoo.com</item> <item>http://de.search.yahoo.com/favicon.ico</item> <item>http://de.search.yahoo.com/search?ei={inputEncoding}&fr=crmas&p={searchTerms}</item> <item>UTF-8</item> <item>http://de-sayt.ff.search.yahoo.com/gossip-de-sayt?output=fxjson&command={searchTerms}</item> </string-array> <string-array name="bing_de_AT" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=de-AT&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="bing_pl_PL" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=pl-PL&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="tut" translatable="false"> <item>TUT.BY</item> <item>tut.by</item> <item>http://www.tut.by/favicon.ico</item> <item>http://search.tut.by/?query={searchTerms}</item> <item>windows-1251</item> <item></item> </string-array> <string-array name="spray" translatable="false"> <item>Spray</item> <item>spray.se</item> <item>http://www.eniro.se/favicon.ico</item> <item>http://www.eniro.se/query?ax=spray&search_word={searchTerms}&what=web</item> <item>ISO-8859-1</item> <item></item> </string-array> <string-array name="wp" translatable="false"> <item>Wirtualna Polska</item> <item>wp.pl</item> <item>http://szukaj.wp.pl/favicon.ico</item> <item>http://szukaj.wp.pl/szukaj.html?szukaj={searchTerms}</item> <item>ISO-8859-2</item> <item></item> </string-array> <string-array name="yahoo_tw" translatable="false"> <item>Yahoo!奇摩</item> <item>tw.yahoo.com</item> <item>http://tw.search.yahoo.com/favicon.ico</item> <item>http://tw.search.yahoo.com/search?ei={inputEncoding}&fr=crmas&p={searchTerms}</item> <item>UTF-8</item> <item></item> </string-array> <string-array name="atlas_cz" translatable="false"> <item>Atlas</item> <item>atlas.cz</item> <item>http://img.atlas.cz/favicon.ico</item> <item>http://search.atlas.cz/?q={searchTerms}</item> <item>windows-1250</item> <item></item> </string-array> <string-array name="bing_en_GB" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=en-GB&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="yahoo_es" translatable="false"> <item>Yahoo! España</item> <item>es.yahoo.com</item> <item>http://es.search.yahoo.com/favicon.ico</item> <item>http://es.search.yahoo.com/search?ei={inputEncoding}&fr=crmas&p={searchTerms}</item> <item>UTF-8</item> <item>http://es-sayt.ff.search.yahoo.com/gossip-es-sayt?output=fxjson&command={searchTerms}</item> </string-array> <string-array name="libero" translatable="false"> <item>Libero</item> <item>libero.it</item> <item>http://arianna.libero.it/favicon.ico</item> <item>http://arianna.libero.it/search/abin/integrata.cgi?query={searchTerms}</item> <item>ISO-8859-1</item> <item></item> </string-array> <string-array name="bing_sv_SE" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=sv-SE&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="yahoo_nz" translatable="false"> <item>Yahoo!Xtra</item> <item>nz.yahoo.com</item> <item>http://nz.search.yahoo.com/favicon.ico</item> <item>http://nz.search.yahoo.com/search?ei={inputEncoding}&fr=crmas&p={searchTerms}</item> <item>UTF-8</item> <item>http://aue-sayt.ff.search.yahoo.com/gossip-nz-sayt?output=fxjson&command={searchTerms}</item> </string-array> <string-array name="terra_es" translatable="false"> <item>Terra</item> <item>terra.es</item> <item>http://buscador.terra.es/favicon.ico</item> <item>http://buscador.terra.es/Default.aspx?query={searchTerms}&source=Search</item> <item>ISO-8859-1</item> <item></item> </string-array> <string-array name="yahoo_nl" translatable="false"> <item>Yahoo! Nederland</item> <item>nl.yahoo.com</item> <item>http://nl.search.yahoo.com/favicon.ico</item> <item>http://nl.search.yahoo.com/search?ei={inputEncoding}&fr=crmas&p={searchTerms}</item> <item>UTF-8</item> <item></item> </string-array> <string-array name="yahoo_no" translatable="false"> <item>Yahoo! Norge</item> <item>no.yahoo.com</item> <item>http://no.search.yahoo.com/favicon.ico</item> <item>http://no.search.yahoo.com/search?ei={inputEncoding}&fr=crmas&p={searchTerms}</item> <item>UTF-8</item> <item></item> </string-array> <string-array name="daum" translatable="false"> <item>Daum</item> <item>daum.net</item> <item>http://search.daum.net/favicon.ico</item> <item>http://search.daum.net/search?q={searchTerms}</item> <item>EUC-KR</item> <item>http://sug.search.daum.net/search_nsuggest?mod=fxjson&q={searchTerms}</item> </string-array> <string-array name="yahoo_fr" translatable="false"> <item>Yahoo! France</item> <item>fr.yahoo.com</item> <item>http://fr.search.yahoo.com/favicon.ico</item> <item>http://fr.search.yahoo.com/search?ei={inputEncoding}&fr=crmas&p={searchTerms}</item> <item>UTF-8</item> <item>http://fr-sayt.ff.search.yahoo.com/gossip-fr-sayt?output=fxjson&command={searchTerms}</item> </string-array> <string-array name="ask_nl" translatable="false"> <item>Ask.com Nederland</item> <item>nl.ask.com</item> <item>http://nl.ask.com/favicon.ico</item> <item>http://nl.ask.com/web?q={searchTerms}</item> <item>UTF-8</item> <item>http://ss.nl.ask.com/query?q={searchTerms}&li=ff</item> </string-array> <string-array name="seznam" translatable="false"> <item>Seznam</item> <item>seznam.cz</item> <item>http://1.im.cz/szn/img/favicon.ico</item> <item>http://search.seznam.cz/?q={searchTerms}</item> <item>UTF-8</item> <item>http://suggest.fulltext.seznam.cz/?dict=fulltext_ff&phrase={searchTerms}&encoding={inputEncoding}&response_encoding=utf-8</item> </string-array> <string-array name="centrum_cz" translatable="false"> <item>Centrum.cz</item> <item>centrum.cz</item> <item>http://img.centrum.cz/6/vy2/o/favicon.ico</item> <item>http://search.centrum.cz/index.php?charset={inputEncoding}&q={searchTerms}</item> <item>UTF-8</item> <item></item> </string-array> <string-array name="eniro_se" translatable="false"> <item>Eniro</item> <item>eniro.se</item> <item>http://eniro.se/favicon.ico</item> <item>http://eniro.se/query?search_word={searchTerms}&what=web_local</item> <item>ISO-8859-1</item> <item></item> </string-array> <string-array name="kvasir" translatable="false"> <item>Kvasir</item> <item>kvasir.no</item> <item>http://www.kvasir.no/img/favicon.ico</item> <item>http://www.kvasir.no/nettsok/searchResult.html?searchExpr={searchTerms}</item> <item>ISO-8859-1</item> <item></item> </string-array> <string-array name="yahoo" translatable="false"> <item>Yahoo!</item> <item>yahoo.com</item> <item>http://search.yahoo.com/favicon.ico</item> <item>http://search.yahoo.com/search?ei={inputEncoding}&fr=crmas&p={searchTerms}</item> <item>UTF-8</item> <item>http://ff.search.yahoo.com/gossip?output=fxjson&command={searchTerms}</item> </string-array> <string-array name="bing_en_IE" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=en-IE&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="bing_pt_PT" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=pt-PT&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="bing_de_CH" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=de-CH&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="bing_nl_NL" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=nl-NL&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="bing_fr_CH" translatable="false"> <item>Bing</item> <item></item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=fr-CH&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="bing_zh_TW" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=zh-TW&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="bing_ru_RU" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=ru-RU&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="bing_en_AU" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=en-AU&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="bing_da_DK" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=da-DK&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="ask_it" translatable="false"> <item>Ask.com Italia</item> <item>it.ask.com</item> <item>http://it.ask.com/favicon.ico</item> <item>http://it.ask.com/web?q={searchTerms}</item> <item>UTF-8</item> <item>http://ss.it.ask.com/query?q={searchTerms}&li=ff</item> </string-array> <string-array name="yandex_ru" translatable="false"> <item>Яндекс</item> <item>yandex.ru</item> <item>http://yandex.ru/favicon.ico</item> <item>http://yandex.ru/yandsearch?text={searchTerms}</item> <item>UTF-8</item> <item>http://suggest.yandex.net/suggest-ff.cgi?part={searchTerms}</item> </string-array> <string-array name="bing_ja_JP" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=ja-JP&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="yahoo_kr" translatable="false"> <item>야후! 코리아</item> <item>kr.yahoo.com</item> <item>http://kr.search.yahoo.com/favicon.ico</item> <item>http://kr.search.yahoo.com/search?ei={inputEncoding}&fr=crmas&p={searchTerms}</item> <item>UTF-8</item> <item>http://kr.atc.search.yahoo.com/atcx.php?property=main&ot=fxjson&ei=utf8&eo=utf8&command={searchTerms}</item> </string-array> <string-array name="ask_de" translatable="false"> <item>Ask.com Deutschland</item> <item>de.ask.com</item> <item>http://de.ask.com/favicon.ico</item> <item>http://de.ask.com/web?q={searchTerms}</item> <item>UTF-8</item> <item>http://ss.de.ask.com/query?q={searchTerms}&li=ff</item> </string-array> <string-array name="yahoo_hk" translatable="false"> <item>Yahoo! Hong Kong</item> <item>hk.yahoo.com</item> <item>http://hk.search.yahoo.com/favicon.ico</item> <item>http://hk.search.yahoo.com/search?ei={inputEncoding}&fr=crmas&p={searchTerms}</item> <item>UTF-8</item> <item></item> </string-array> <string-array name="bing_fr_FR" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=fr-FR&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="in" translatable="false"> <item>in.gr</item> <item>in.gr</item> <item>http://www.in.gr/favicon.ico</item> <item>http://find.in.gr/?qs={searchTerms}</item> <item>ISO-8859-7</item> <item></item> </string-array> <string-array name="bing_nb_NO" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=nb-NO&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="yahoo_sg" translatable="false"> <item>Yahoo! Singapore</item> <item>sg.yahoo.com</item> <item>http://sg.search.yahoo.com/favicon.ico</item> <item>http://sg.search.yahoo.com/search?ei={inputEncoding}&fr=crmas&p={searchTerms}</item> <item>UTF-8</item> <item>http://sg-sayt.ff.search.yahoo.com/gossip-sg-sayt?output=fxjson&command={searchTerms}</item> </string-array> <string-array name="yahoo_se" translatable="false"> <item>Yahoo! Sverige</item> <item>se.yahoo.com</item> <item>http://se.search.yahoo.com/favicon.ico</item> <item>http://se.search.yahoo.com/search?ei={inputEncoding}&fr=crmas&p={searchTerms}</item> <item>UTF-8</item> <item></item> </string-array> <string-array name="bing_de_DE" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=de-DE&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="search_de_CH" translatable="false"> <item>search.ch</item> <item>search.ch</item> <item>http://www.search.ch/favicon.ico</item> <item>http://www.search.ch/index.de.html?q={searchTerms}</item> <item>ISO-8859-1</item> <item></item> </string-array> <string-array name="mynet" translatable="false"> <item>MYNET</item> <item>mynet.com</item> <item>http://img.mynet.com/mynetfavori.ico</item> <item>http://arama.mynet.com/search.aspx?q={searchTerms}&pg=q</item> <item>windows-1254</item> <item></item> </string-array> <string-array name="search_fr_CH" translatable="false"> <item>search.ch</item> <item></item> <item>http://www.search.ch/favicon.ico</item> <item>http://www.search.ch/index.fr.html?q={searchTerms}</item> <item>ISO-8859-1</item> <item></item> </string-array> <string-array name="virgilio" translatable="false"> <item>Virgilio</item> <item>virgilio.it</item> <item>http://ricerca.alice.it/favicon.ico</item> <item>http://ricerca.alice.it/ricerca?qs={searchTerms}</item> <item>ISO-8859-1</item> <item></item> </string-array> <string-array name="bing_en_SG" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=en-SG&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="yahoo_it" translatable="false"> <item>Yahoo! Italia</item> <item>it.yahoo.com</item> <item>http://it.search.yahoo.com/favicon.ico</item> <item>http://it.search.yahoo.com/search?ei={inputEncoding}&fr=crmas&p={searchTerms}</item> <item>UTF-8</item> <item>http://it-sayt.ff.search.yahoo.com/gossip-it-sayt?output=fxjson&command={searchTerms}</item> </string-array> <string-array name="yahoo_at" translatable="false"> <item>Yahoo! Suche</item> <item>at.yahoo.com</item> <item>http://at.search.yahoo.com/favicon.ico</item> <item>http://at.search.yahoo.com/search?ei={inputEncoding}&fr=crmas&p={searchTerms}</item> <item>UTF-8</item> <item></item> </string-array> <string-array name="yahoo_au" translatable="false"> <item>Yahoo!7</item> <item>au.yahoo.com</item> <item>http://au.search.yahoo.com/favicon.ico</item> <item>http://au.search.yahoo.com/search?ei={inputEncoding}&fr=crmas&p={searchTerms}</item> <item>UTF-8</item> <item>http://aue-sayt.ff.search.yahoo.com/gossip-au-sayt?output=fxjson&command={searchTerms}</item> </string-array> <string-array name="bing_pt_BR" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=pt-BR&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="bing" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <string-array name="netsprint" translatable="false"> <item>NetSprint</item> <item>netsprint.pl</item> <item>http://netsprint.pl/favicon.ico</item> <item>http://www.netsprint.pl/serwis/search?q={searchTerms}</item> <item>UTF-8</item> <item></item> </string-array> <string-array name="naver" translatable="false"> <item>네이버</item> <item>naver.com</item> <item>http://search.naver.com/favicon.ico</item> <item>http://search.naver.com/search.naver?ie={inputEncoding}&query={searchTerms}</item> <item>UTF-8</item> <item>http://ac.search.naver.com/autocompl?m=s&ie={inputEncoding}&oe=utf-8&q={searchTerms}</item> </string-array> <string-array name="bing_en_ZA" translatable="false"> <item>Bing</item> <item>bing.com</item> <item>http://www.bing.com/s/wlflag.ico</item> <item>http://www.bing.com/search?setmkt=en-ZA&q={searchTerms}</item> <item>UTF-8</item> <item>http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item> </string-array> <!-- add for CMCC 139 search --> <string-array name="cmcc_cn" translatable="false"> <item>139搜索</item> <item>s.139.com</item> <item>http://s.139.com/favicon.ico</item> <item>http://s.139.com/search.do?q={searchTerms}&category=downloadable|web|browseable&tid=2123,2124,2125,2126&fr=portalcustom2</item> <item>GB2312</item> <item></item> </string-array> <string-array name="cmcc" translatable="false"> <item>139 Search</item> <item>s.139.com</item> <item>http://s.139.com/favicon.ico</item> <item>http://s.139.com/search.do?q={searchTerms}&category=downloadable|web|browseable&tid=2123,2124,2125,2126&fr=portalcustom2</item> <item>UTF-8</item> <item></item> </string-array> <!-- end add --> <!-- Custom search engines used from overlays --> <string-array name="custom_search_engine_1" translatable="false"> </string-array> <string-array name="custom_search_engine_2" translatable="false"> </string-array> <string-array name="custom_search_engine_3" translatable="false"> </string-array> <string-array name="custom_search_engine_4" translatable="false"> </string-array> <string-array name="custom_search_engine_5" translatable="false"> </string-array> <string-array name="custom_search_engine_6" translatable="false"> </string-array> <string-array name="custom_search_engine_7" translatable="false"> </string-array> <string-array name="custom_search_engine_8" translatable="false"> </string-array> <string-array name="custom_search_engine_9" translatable="false"> </string-array> <string-array name="custom_search_engine_10" translatable="false"> </string-array> <string-array name="custom_search_engine_11" translatable="false"> </string-array> <string-array name="custom_search_engine_12" translatable="false"> </string-array> <string-array name="custom_search_engine_13" translatable="false"> </string-array> <string-array name="custom_search_engine_14" translatable="false"> </string-array> <string-array name="custom_search_engine_15" translatable="false"> </string-array> <string-array name="custom_search_engine_16" translatable="false"> </string-array> <string-array name="custom_search_engine_17" translatable="false"> </string-array> <string-array name="custom_search_engine_18" translatable="false"> </string-array> <string-array name="custom_search_engine_19" translatable="false"> </string-array> <string-array name="custom_search_engine_20" translatable="false"> </string-array> </resources>
donottranslate-search_engines.xml中的search_engines配置,注意每种语言values下都有一个donottranslate-search_engines 都要配置,否则切换语言会导致引擎列表不一样
donottranslate-search_engines.xml<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <string-array name="search_engines" translatable="false"> <item>cmcc</item> <item>baidu</item> <item>yahoo</item> <item>bing</item> </string-array> <string name="default_search_engine_value">baidu</string> </resources>
SearchEngines.getSearchEngineInfos(context)将search_engines配置的item拿到,然后去all_search_engines.xml中匹配,获取对应的SearchEngineInfo,然后显示引擎列表。
public SearchEngineInfo(Context context, String name) throws IllegalArgumentException { mName = name; final Resources res = context.getResources(); String packageName = R.class.getPackage().getName(); int id_data = res.getIdentifier(name, "array", packageName); if(id_data == 0) { id_data = res.getIdentifier(name, "array", context.getPackageName()); } if (id_data == 0) { throw new IllegalArgumentException("No resources found for " + name); } mSearchEngineData = res.getStringArray(id_data); if (mSearchEngineData == null) { throw new IllegalArgumentException("No data found for " + name); } if (mSearchEngineData.length != NUM_FIELDS) { throw new IllegalArgumentException( name + " has invalid number of fields - " + mSearchEngineData.length); } if (TextUtils.isEmpty(mSearchEngineData[FIELD_SEARCH_URI])) { throw new IllegalArgumentException(name + " has an empty search URI"); } // Add the current language/country information to the URIs. Locale locale = context.getResources().getConfiguration().locale; StringBuilder language = new StringBuilder(locale.getLanguage()); if (!TextUtils.isEmpty(locale.getCountry())) { language.append(‘-‘); language.append(locale.getCountry()); } String language_str = language.toString(); mSearchEngineData[FIELD_SEARCH_URI] = mSearchEngineData[FIELD_SEARCH_URI].replace(PARAMETER_LANGUAGE, language_str); mSearchEngineData[FIELD_SUGGEST_URI] = mSearchEngineData[FIELD_SUGGEST_URI].replace(PARAMETER_LANGUAGE, language_str); // Default to UTF-8 if not specified. String enc = mSearchEngineData[FIELD_ENCODING]; if (TextUtils.isEmpty(enc)) { enc = "UTF-8"; mSearchEngineData[FIELD_ENCODING] = enc; } // Add the input encoding method to the URI. mSearchEngineData[FIELD_SEARCH_URI] = mSearchEngineData[FIELD_SEARCH_URI].replace(PARAMETER_INPUT_ENCODING, enc); mSearchEngineData[FIELD_SUGGEST_URI] = mSearchEngineData[FIELD_SUGGEST_URI].replace(PARAMETER_INPUT_ENCODING, enc); }
时间: 2024-11-08 10:01:31