android漢字轉拼音
❶ android中怎麼將漢字轉化為拼音的代碼
沒有什麼好辦法``因為漢字在系統中的存儲與它對應的拼音沒有什麼關系,所以只能通過一個漢字和拼音的對照庫來進行.
你的採納是我前進的動力,
記得好評和採納,答題不易,互相幫助,
手機提問的朋友在客戶端右上角評價點(滿意)即可.
如果你認可我的回答,請及時點擊(採納為滿意回答)按鈕!!
❷ android怎麼獲取輸入漢字的拼音
static final int GB_SP_DIFF = 160;
// 存放國標一級漢字不同讀音的起始區位碼
static final int[] secPosValueList = { 1601, 1637, 1833, 2078, 2274, 2302, 2433, 2594, 2787, 3106, 3212, 3472, 3635, 3722, 3730, 3858, 4027, 4086, 4390, 4558, 4684, 4925,
5249, 5600 };
// 存放國標一級漢字不同讀音的起始區位碼對應讀音
static final char[] firstLetter = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'w', 'x', 'y', 'z' };
// 獲取一個字元串的拼音碼
public static String getFirstLetter(String oriStr) {
String str = oriStr.toLowerCase();
StringBuffer buffer = new StringBuffer();
char ch;
char[] temp;
for (int i = 0; i < str.length(); i++) { // 依次處理str中每個字元
ch = str.charAt(i);
temp = new char[] { ch };
byte[] uniCode = new String(temp).getBytes();
if (uniCode[0] < 128 && uniCode[0] > 0) { // 非漢字
buffer.append(temp);
} else {
buffer.append(convert(uniCode));
}
}
return buffer.toString();
}
// 獲取一個漢字的拼音碼
public static Character getFirstLetter(char ch) {
byte[] uniCode = null;
try {
uniCode = String.valueOf(ch).getBytes("GBK");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return null;
}
if (uniCode[0] &0xff< 128 && uniCode[0]&0xff > 0) { // 非漢字
return null;
} else {
return convert(uniCode);
}
}
/**
* 獲取一個漢字的拼音首字母。 GB碼兩個位元組分別減去160,轉換成10進制碼組合就可以得到區位碼
* 例如漢字「你」的GB碼是0xC4/0xE3,分別減去0xA0(160)就是0x24/0x43
* 0x24轉成10進制就是36,0x43是67,那麼它的區位碼就是3667,在對照表中讀音為『n』
*/
static char convert(byte[] bytes) {
char result = '-';
int secPosValue = 0;
int i;
for (i = 0; i < bytes.length; i++) {
bytes[i] -= GB_SP_DIFF;
}
secPosValue = bytes[0] * 100 + bytes[1];
for (i = 0; i < 23; i++) {
if (secPosValue >= secPosValueList[i] && secPosValue < secPosValueList[i + 1]) {
result = firstLetter[i];
break;
}
}
return result;
}
❸ 輕巧的漢字轉拼音庫 TinyPinyin 在Android上的使用
原文: https://blog.csdn.net/uyy203/article/details/54632495
最近發現一個相當輕巧,運行速度很快的漢字轉拼音庫——TinyPinyin,這個漢字轉拼音庫比上一篇講述列表按照A-Z的規則排序的文章所使用的漢字轉拼音庫運行速度還要快10倍以上。
主要特性
生成的拼音不包含聲調和方言,均為大寫;
支持自定義詞典;
執行效率很高(Pinyin4J 的 4~16 倍);
很低的內存佔用(不添加詞典時小於 30KB)。
主導入Gradle
使用方法
詞典API
github: https://github.com/Cedric-Xuan/Sort
❹ android里如何將漢字轉換成拼音字母
這個問題跟android沒有關系,最好是改成java里如何將漢字轉換成拼音字母
有一個類庫:pinyin4j
還有例子http://hi..com/ogezkwhalp/item/eb325bc8d1d4d46bf7c95dbf
❺ android 如何輸入首字母進行地址城市模糊檢索
Android中ListView的A-Z字母排序和過濾搜索功能並且實現漢字轉成拼音的功能,一般對聯系人,城市列表等實現A-Z的排序,因為聯系人和城市列表可以直接從資料庫中獲取它的漢字拼音,而對於一般的數據,實現A-Z的排序,基實只需要將漢字轉換成拼音就行了。
以下為步驟:
SortModel 一個實體類,裡面一個是ListView的name,另一個就是顯示的name拼音的首字母。
2.SideBar類就是ListView右側的字母索引View,需要使用setTextView(TextView mTextDialog)來設置用來顯示當前按下的字母的TextView,以及使用方法來設置回調介面,在回調方法onTouchingLetterChanged(String s)中來處理不同的操作。
3.CharacterParser這個類是將漢字轉換成拼音的類,該拼音沒有聲調的,該類是單例類,其中定義了三個方法,在這個demo中用到的是getSelling(String chs)方法,將片語轉換成拼音。
4.ClearEditText類是自定義的一個在右側有刪除圖片的EditText,當然也可以用Android原生的EditText,這里就不貼上代碼了Android 帶清除功能的輸入框控制項ClearEditText,仿IOS的輸入框。
5.SortAdapter 數據的適配器類,該類需要實現SectionIndexer介面,該介面是用來控制ListView分組的。
6.最後運行效果