本文整理汇总了Java中android.text.style.TextAppearanceSpan类的典型用法代码示例。如果您正苦于以下问题:Java TextAppearanceSpan类的具体用法?Java TextAppearanceSpan怎么用?Java TextAppearanceSpan使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TextAppearanceSpan类属于android.text.style包,在下文中一共展示了TextAppearanceSpan类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: highlightTerm
import android.text.style.TextAppearanceSpan; //导入依赖的package包/类
private void highlightTerm(TextView tv, String query, String originalString){
if (query != null && !query.isEmpty()) {
int startPos = originalString.toLowerCase().indexOf(query.toLowerCase());
int endPos = startPos + query.length();
if (startPos != -1) {
Spannable spannable = new SpannableString(originalString);
ColorStateList blackColor = new ColorStateList(new int[][]{new int[]{}}, new int[]{Color.BLACK});
TextAppearanceSpan highlightSpan = new TextAppearanceSpan(null, Typeface.BOLD, -1, blackColor, null);
spannable.setSpan(highlightSpan, startPos, endPos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(spannable);
} else {
tv.setText(originalString);
}
} else {
tv.setText(originalString);
}
}
示例2: QuickConversationAdapter
import android.text.style.TextAppearanceSpan; //导入依赖的package包/类
public QuickConversationAdapter(final Context context, List<Message> messageList, EmojiconHandler emojiconHandler) {
this.context = context;
this.emojiconHandler = emojiconHandler;
this.contactService = new AppContactService(context);
this.messageDatabaseService = new MessageDatabaseService(context);
this.messageList = messageList;
contactImageLoader = new ImageLoader(context, ImageUtils.getLargestScreenDimension((Activity) context)) {
@Override
protected Bitmap processBitmap(Object data) {
return contactService.downloadContactImage((Activity) context, (Contact) data);
}
};
contactImageLoader.addImageCache(((FragmentActivity) context).getSupportFragmentManager(), 0.1f);
contactImageLoader.setImageFadeIn(false);
channelImageLoader = new ImageLoader(context, ImageUtils.getLargestScreenDimension((Activity) context)) {
@Override
protected Bitmap processBitmap(Object data) {
return contactService.downloadGroupImage((Activity) context, (Channel) data);
}
};
channelImageLoader.addImageCache(((FragmentActivity) context).getSupportFragmentManager(), 0.1f);
channelImageLoader.setImageFadeIn(false);
final String alphabet = context.getString(R.string.alphabet);
mAlphabetIndexer = new AlphabetIndexer(null, 1, alphabet);
highlightTextSpan = new TextAppearanceSpan(context, R.style.searchTextHiglight);
}
示例3: ChannelAdapter
import android.text.style.TextAppearanceSpan; //导入依赖的package包/类
/**
* Instantiates a new Contacts Adapter.
*
* @param context A context that has access to the app's layout.
*/
public ChannelAdapter(Context context) {
super(context, null, 0);
this.context = context;
// Stores inflater for use later
mInflater = LayoutInflater.from(context);
final String alphabet = context.getString(R.string.alphabet);
// Instantiates a new AlphabetIndexer bound to the column used to sort contact names.
// The cursor is left null, because it has not yet been retrieved.
mAlphabetIndexer = new AlphabetIndexer(null, 1, alphabet);
// Defines a span for highlighting the part of a display name that matches the search
// string
highlightTextSpan = new TextAppearanceSpan(getActivity(), R.style.searchTextHiglight);
}
示例4: ContactsAdapter
import android.text.style.TextAppearanceSpan; //导入依赖的package包/类
/**
* Instantiates a new Contacts Adapter.
*
* @param context A context that has access to the app's layout.
*/
public ContactsAdapter(Context context) {
super(context, null, 0);
// Stores inflater for use later
mInflater = LayoutInflater.from(context);
// Loads a string containing the English alphabet. To fully localize the app, provide a
// strings.xml file in res/values-<x> directories, where <x> is a locale. In the file,
// define a string with android:name="alphabet" and contents set to all of the
// alphabetic characters in the language in their proper sort order, in upper case if
// applicable.
final String alphabet = context.getString(R.string.alphabet);
// Instantiates a new AlphabetIndexer bound to the column used to sort contact names.
// The cursor is left null, because it has not yet been retrieved.
mAlphabetIndexer = new AlphabetIndexer(null, ContactsQuery.SORT_KEY, alphabet);
// Defines a span for highlighting the part of a display name that matches the search
// string
highlightTextSpan = new TextAppearanceSpan(getActivity(), R.style.searchTextHiglight);
}
示例5: ContactsAdapter
import android.text.style.TextAppearanceSpan; //导入依赖的package包/类
/**
* Instantiates a new Contacts Adapter.
*
* @param context A context that has access to the app's layout.
*/
public ContactsAdapter(Context context) {
super(context, null, 0);
this.context = context;
userIdList = new ArrayList<String>();
// Stores inflater for use later
mInflater = LayoutInflater.from(context);
// Loads a string containing the English alphabet. To fully localize the app, provide a
// strings.xml file in res/values-<x> directories, where <x> is a locale. In the file,
// define a string with android:name="alphabet" and contents set to all of the
// alphabetic characters in the language in their proper sort order, in upper case if
// applicable.
final String alphabet = context.getString(R.string.alphabet);
// Instantiates a new AlphabetIndexer bound to the column used to sort contact names.
// The cursor is left null, because it has not yet been retrieved.
mAlphabetIndexer = new AlphabetIndexer(null, 1, alphabet);
// Defines a span for highlighting the part of a display name that matches the search
// string
highlightTextSpan = new TextAppearanceSpan(context, R.style.searchTextHiglight);
}
示例6: ContactsAdapter
import android.text.style.TextAppearanceSpan; //导入依赖的package包/类
/**
* Instantiates a new Contacts Adapter.
*
* @param context A context that has access to the app's layout.
*/
public ContactsAdapter(Context context) {
super(context, null, 0);
this.context = context;
// Stores inflater for use later
mInflater = LayoutInflater.from(context);
// Loads a string containing the English alphabet. To fully localize the app, provide a
// strings.xml file in res/values-<x> directories, where <x> is a locale. In the file,
// define a string with android:name="alphabet" and contents set to all of the
// alphabetic characters in the language in their proper sort order, in upper case if
// applicable.
final String alphabet = context.getString(R.string.alphabet);
// Instantiates a new AlphabetIndexer bound to the column used to sort contact names.
// The cursor is left null, because it has not yet been retrieved.
mAlphabetIndexer = new AlphabetIndexer(null, 1, alphabet);
// Defines a span for highlighting the part of a display name that matches the search
// string
highlightTextSpan = new TextAppearanceSpan(getActivity(), R.style.searchTextHiglight);
}
示例7: setTitleAndImage
import android.text.style.TextAppearanceSpan; //导入依赖的package包/类
private void setTitleAndImage(RecordingCardView cardView, ScheduledRecording recording) {
Channel channel = mChannelDataManager.getChannel(recording.getChannelId());
SpannableString title = recording.getProgramTitleWithEpisodeNumber(mContext) == null ?
null : new SpannableString(recording.getProgramTitleWithEpisodeNumber(mContext));
if (TextUtils.isEmpty(title)) {
title = new SpannableString(channel != null ? channel.getDisplayName()
: mContext.getResources().getString(R.string.no_program_information));
} else {
String programTitle = recording.getProgramTitle();
title.setSpan(new TextAppearanceSpan(mContext,
R.style.text_appearance_card_view_episode_number),
programTitle == null ? 0 : programTitle.length(), title.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
String imageUri = recording.getProgramPosterArtUri();
boolean isChannelLogo = false;
if (TextUtils.isEmpty(imageUri)) {
imageUri = channel != null ?
TvContract.buildChannelLogoUri(channel.getId()).toString() : null;
isChannelLogo = true;
}
cardView.setTitle(title);
cardView.setImageUri(imageUri, isChannelLogo);
}
示例8: getTitleFromProgram
import android.text.style.TextAppearanceSpan; //导入依赖的package包/类
/**
* Returns program title with episode number. If the program is null, returns channel name.
*/
protected CharSequence getTitleFromProgram(BaseProgram program, Channel channel) {
String titleWithEpisodeNumber = program.getTitleWithEpisodeNumber(getContext());
SpannableString title = titleWithEpisodeNumber == null ? null
: new SpannableString(titleWithEpisodeNumber);
if (TextUtils.isEmpty(title)) {
title = new SpannableString(channel != null ? channel.getDisplayName()
: getContext().getResources().getString(
R.string.no_program_information));
} else {
String programTitle = program.getTitle();
title.setSpan(new TextAppearanceSpan(getContext(),
R.style.text_appearance_card_view_episode_number), programTitle == null ? 0
: programTitle.length(), title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return title;
}
示例9: onBindViewHolder
import android.text.style.TextAppearanceSpan; //导入依赖的package包/类
@Override
public void onBindViewHolder(FindSearchAdapter.ItemHolder holder, int position) {
// String typeAndWhoStr = "<font color=\"#666666\"> ( "
// + mDatas.get(position).getType()
// + " via." + mDatas.get(position).getWho() + ") </font>";
int textColor = Color.parseColor("#4d000000");
String textStr = mDatas.get(position).getDesc() + " ("
+ " via. " + mDatas.get(position).getWho() + ")";
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(textStr);
// spannableStringBuilder.setSpan(new ForegroundColorSpan(textColor),
// textStr.lastIndexOf("("), textStr.lastIndexOf(")") + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spannableStringBuilder.setSpan(new TextAppearanceSpan(context, R.style.text_span_style),
textStr.lastIndexOf("("), textStr.lastIndexOf(")") + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
holder.searchResultContentTv.setText(spannableStringBuilder);
// holder.searchResultContentTv.setText(mDatas.get(position).getDesc() + " ("
// + mDatas.get(position).getType()
// + " via." + mDatas.get(position).getWho() + ")");
// 将数据保存在itemView的Tag中,以便点击时进行获取
holder.itemView.setTag(mDatas.get(position));
}
示例10: createCardItemText
import android.text.style.TextAppearanceSpan; //导入依赖的package包/类
private TextView createCardItemText(BaseGankData baseGankData) {
TextView itemText = (TextView) LayoutInflater.from(this.context)
.inflate(R.layout.view_card_item, null);
itemText.setPadding(this.cardItemPadding, this.cardItemPadding, this.cardItemPadding,
this.cardItemPadding);
String content = baseGankData.desc.trim() +
" " +
String.format(this.viaModel, baseGankData.who);
SpannableStringBuilder ssb = new SpannableStringBuilder(content);
ssb.setSpan(new TextAppearanceSpan("serif", Typeface.ITALIC, this.viaTextSize,
this.viaColorStateList, this.viaColorStateList), content.indexOf(this.viaModelKey),
content.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
itemText.setText(ssb);
itemText.setTag(R.id.tag_card_item_url, baseGankData.url);
itemText.setTag(R.id.tag_card_item_desc, baseGankData.desc.trim());
itemText.setTag(R.id.tag_card_item_type, baseGankData.type);
itemText.setOnClickListener(v -> {
if (DailyDetailAdapter.this.onCardItemClickListener != null) {
DailyDetailAdapter.this.onCardItemClickListener.onCardItemOnClick(
(String) v.getTag(R.id.tag_card_item_type),
(String) v.getTag(R.id.tag_card_item_desc),
(String) v.getTag(R.id.tag_card_item_url));
}
});
return itemText;
}
示例11: ContactsAdapter
import android.text.style.TextAppearanceSpan; //导入依赖的package包/类
/**
* Instantiates a new Contacts Adapter.
* @param context A context that has access to the app's layout.
*/
public ContactsAdapter(Context context) {
super(context, null, 0);
// Stores inflater for use later
mInflater = LayoutInflater.from(context);
// Loads a string containing the English alphabet. To fully localize the app, provide a
// strings.xml file in res/values-<x> directories, where <x> is a locale. In the file,
// define a string with android:name="alphabet" and contents set to all of the
// alphabetic characters in the language in their proper sort order, in upper case if
// applicable.
final String alphabet = context.getString(R.string.alphabet);
// Instantiates a new AlphabetIndexer bound to the column used to sort contact names.
// The cursor is left null, because it has not yet been retrieved.
mAlphabetIndexer = new AlphabetIndexer(null, ContactsQuery.SORT_KEY, alphabet);
// Defines a span for highlighting the part of a display name that matches the search
// string
highlightTextSpan = new TextAppearanceSpan(getActivity(), R.style.searchTextHiglight);
}
示例12: highlight
import android.text.style.TextAppearanceSpan; //导入依赖的package包/类
private void highlight(String search, String originalText, TextView textView) {
int startPos = originalText.toLowerCase(Locale.US).indexOf(search.toLowerCase(Locale.US));
int endPos = startPos + search.length();
if(startPos != -1){
Spannable spannable = new SpannableString(originalText);
ColorStateList yellowColor = new ColorStateList(new int[][]{new int[]{}}, new
int[]{ContextCompat.getColor(mContext, R.color.overscroll_color)});
TextAppearanceSpan highlightSpan = new TextAppearanceSpan(null, Typeface.BOLD, -1,
yellowColor, null);
spannable.setSpan(highlightSpan, startPos, endPos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(spannable);
} else {
textView.setText(originalText);
}
}
示例13: onCreate
import android.text.style.TextAppearanceSpan; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
storyLister = new StoryLister(this);
storyList = (ListView) findViewById(R.id.storylist);
storyListAdapter = new StoryListAdapter();
storyList.setAdapter(storyListAdapter);
titleStyle = new TextAppearanceSpan(this, R.style.story_title);
authorStyle = new TextAppearanceSpan(this, R.style.story_author);
headlineStyle = new TextAppearanceSpan(this, R.style.story_headline);
descriptionStyle = new TextAppearanceSpan(this, R.style.story_description);
saveTimeStyle = new TextAppearanceSpan(this, R.style.story_save_time);
downloadTimeStyle = new TextAppearanceSpan(this, R.style.story_download_time);
coverImageCache = new LruCache<String,Bitmap>(10);
}
示例14: formatPictureMessage
import android.text.style.TextAppearanceSpan; //导入依赖的package包/类
public CharSequence formatPictureMessage(Context context) {
final TextAppearanceSpan notificationSubjectSpan = new TextAppearanceSpan(
context, R.style.NotificationPrimaryText);
// Change multiple newlines (with potential white space between), into a single new line
final String message =
!TextUtils.isEmpty(mMessage) ? mMessage.replaceAll("\\n\\s+", "\n") : "";
// Show the subject or the message (if no subject)
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
if (!TextUtils.isEmpty(mSubject)) {
spannableStringBuilder.append(mSubject);
spannableStringBuilder.setSpan(notificationSubjectSpan, 0, mSubject.length(), 0);
}
if (message.length() > 0 && spannableStringBuilder.length() == 0) {
spannableStringBuilder.append(message);
spannableStringBuilder.setSpan(notificationSubjectSpan, 0, message.length(), 0);
}
return spannableStringBuilder;
}
示例15: formatSenders
import android.text.style.TextAppearanceSpan; //导入依赖的package包/类
private static CharSequence formatSenders(Context context,
ArrayList<NotificationInfo> senders) {
final TextAppearanceSpan notificationSenderSpan = new TextAppearanceSpan(
context, R.style.NotificationPrimaryText);
String separator = context.getString(R.string.enumeration_comma); // ", "
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
int len = senders.size();
for (int i = 0; i < len; i++) {
if (i > 0) {
spannableStringBuilder.append(separator);
}
spannableStringBuilder.append(senders.get(i).mSender.getName());
}
spannableStringBuilder.setSpan(notificationSenderSpan, 0,
spannableStringBuilder.length(), 0);
return spannableStringBuilder;
}