本文整理汇总了Java中android.text.SpannableString.valueOf方法的典型用法代码示例。如果您正苦于以下问题:Java SpannableString.valueOf方法的具体用法?Java SpannableString.valueOf怎么用?Java SpannableString.valueOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.SpannableString
的用法示例。
在下文中一共展示了SpannableString.valueOf方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getformatedSearchSnippet
import android.text.SpannableString; //导入方法依赖的package包/类
public CharSequence getformatedSearchSnippet() {
//TODO implement improved snippet function
String CleanedSearchString = " " + ArabicUtilities.cleanTextForSearchingWthStingBuilder(searchString) + " ";
StringBuilder cleanedUnformattedPage = new StringBuilder(ArabicUtilities.cleanTextForSearchingWthStingBuilder(unformatedPage));
int firstMatchStart = cleanedUnformattedPage.indexOf(CleanedSearchString);
cleanedUnformattedPage.delete(0, Math.max(firstMatchStart - 100, 0));
cleanedUnformattedPage.delete(
Math.min(firstMatchStart + CleanedSearchString.length() + 100, cleanedUnformattedPage.length())
, cleanedUnformattedPage.length());
cleanedUnformattedPage.insert(0, "...");
cleanedUnformattedPage.append("...");
Spannable snippet = SpannableString.
valueOf(cleanedUnformattedPage.toString());
int index = TextUtils.indexOf(snippet, CleanedSearchString);
while (index >= 0) {
snippet.setSpan(new BackgroundColorSpan(0xFF8B008B), index, index
+ CleanedSearchString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
index = TextUtils.indexOf(snippet, CleanedSearchString, index + CleanedSearchString.length());
}
return snippet;
}
示例2: addLinks
import android.text.SpannableString; //导入方法依赖的package包/类
/**
* Scans the text of the provided TextView and turns all occurrences of
* the link types indicated in the mask into clickable links. If matches
* are found the movement method for the TextView is set to
* LinkMovementMethod.
*/
public static final boolean addLinks(TextView text, int mask, ColorStateList linkColor, ColorStateList bgColor, QMUIOnSpanClickListener l) {
if (mask == 0) {
return false;
}
CharSequence t = text.getText();
if (t instanceof Spannable) {
if (addLinks((Spannable) t, mask, linkColor, bgColor, l)) {
addLinkMovementMethod(text);
return true;
}
return false;
} else {
SpannableString s = SpannableString.valueOf(t);
if (addLinks(s, mask, linkColor, bgColor, l)) {
addLinkMovementMethod(text);
text.setText(s);
return true;
}
return false;
}
}
示例3: setUrlText
import android.text.SpannableString; //导入方法依赖的package包/类
/**
* Sets (and highlights) the URL text of the second line of the omnibox suggestion.
*
* @param result The suggestion containing the URL.
* @return Whether the URL was highlighted based on the user query.
*/
private boolean setUrlText(OmniboxResultItem result) {
OmniboxSuggestion suggestion = result.getSuggestion();
Spannable str = SpannableString.valueOf(suggestion.getDisplayText());
boolean hasMatch = applyHighlightToMatchRegions(
str, suggestion.getDisplayTextClassifications());
showDescriptionLine(str, true);
return hasMatch;
}
示例4: convertNormalStringToSpannableString
import android.text.SpannableString; //导入方法依赖的package包/类
/**
* 解析表情
* @param message
* @return
*/
private CharSequence convertNormalStringToSpannableString(String message) {
/* // Direct use of Pattern:
Pattern p = Pattern.compile("Hello, (\\S+)");
Matcher m = p.matcher(inputString);
while (m.find()) { // Find each match in turn; String can't do this.
String name = m.group(1); // Access a submatch group; String can't do this.
}*/
/*//不知道是干嘛的。。
SpannableString spannableString ;
if(message.startsWith("[") && message.endsWith("]")){
spannableString = SpannableString.valueOf(message +" ");
}else{
spannableString = SpannableString.valueOf(message);
}*/
SpannableString spannableString = SpannableString.valueOf(message);
//匹配 表情 字符串
Matcher matcher = patter.matcher(spannableString);
while(matcher.find()){
String keyStr = matcher.group(0);
int start = matcher.start();
int end = matcher.end();
//过长就不是表情了 所以只检测长度小于8的字符串
if(end - start <8){
//判断是否有此表情
if(mFaceMap.containsKey(keyStr)){
int faceId = mFaceMap.get(keyStr);
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),faceId);
if(bitmap != null){
ImageSpan imageSpan = new ImageSpan(context, bitmap);
spannableString.setSpan(imageSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
}
return spannableString;
}
示例5: addLinks
import android.text.SpannableString; //导入方法依赖的package包/类
/**
* Scans the text of the provided TextView and turns all occurrences of
* the link types indicated in the mask into clickable links. If matches
* are found the movement method for the TextView is set to
* LinkMovementMethod.
*/
public static boolean addLinks(TextView text, int mask, ColorStateList linkColor, ColorStateList bgColor, QMUIOnSpanClickListener l) {
if (mask == 0) {
return false;
}
CharSequence t = text.getText();
if (t instanceof Spannable) {
if (addLinks((Spannable) t, mask, linkColor, bgColor, l)) {
addLinkMovementMethod(text);
return true;
}
return false;
} else {
SpannableString s = SpannableString.valueOf(t);
if (addLinks(s, mask, linkColor, bgColor, l)) {
addLinkMovementMethod(text);
text.setText(s);
return true;
}
return false;
}
}