List of usage examples for android.text SpannableString setSpan
public void setSpan(Object what, int start, int end, int flags)
From source file:net.bible.android.view.util.widget.BookmarkStyleAdapterHelper.java
/** * Replace first character of text with image *//*from ww w .j a v a2s .c o m*/ private CharSequence addImageAtStart(String text, int drawableImage, Context context) { ImageSpan imageSpan = new ImageSpan(context, drawableImage, ImageSpan.ALIGN_BASELINE); final SpannableString spannableString = new SpannableString(text); spannableString.setSpan(imageSpan, 0, 1, SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }
From source file:ru.tinkoff.acquiring.sample.ui.PaymentResultActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_payment_result); getSupportActionBar().setDisplayHomeAsUpEnabled(true); final TextView textView = (TextView) findViewById(R.id.tv_confirm); Intent intent = getIntent();//from w w w.j a va 2 s.co m if (intent.hasExtra(EXTRA_PRICE)) { final Money price = (Money) intent.getSerializableExtra(EXTRA_PRICE); final SpannableString coloredPrice = new SpannableString(price.toString()); coloredPrice.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.colorPrimary)), 0, coloredPrice.length(), SpannedString.SPAN_INCLUSIVE_INCLUSIVE); final String text = getString(R.string.payment_result_success, coloredPrice); textView.setText(text); } else { String cardId = intent.getStringExtra(EXTRA_CARD_ID); final String text = getString(R.string.attachment_result_success, cardId); textView.setText(text); } }
From source file:com.normalexception.app.rx8club.view.profile.ProfileViewArrayAdapter.java
public View getView(int position, View convertView, ViewGroup parent) { View vi = convertView;/*from w ww .jav a2 s . c o m*/ if (vi == null) { vi = new TextView(sourceFragment.getActivity()); } TextView tv = (TextView) vi; final ProfileModel pm = data.get(position); String text = String.format("%s\n%s", pm.getName(), pm.getText()); SpannableString spanString = new SpannableString(text); spanString.setSpan(new StyleSpan(Typeface.BOLD), 0, text.indexOf("\n"), 0); spanString.setSpan(new StyleSpan(Typeface.ITALIC), text.indexOf("\n") + 1, text.length(), 0); tv.setText(spanString); tv.setPadding(1, 10, 1, 10); tv.setBackgroundColor(Color.DKGRAY); tv.setTextColor(Color.WHITE); tv.setTextSize(10); tv.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Bundle args = new Bundle(); args.putString("link", pm.getLink()); args.putString("title", pm.getName()); FragmentUtils.fragmentTransaction(sourceFragment.getActivity(), ThreadFragment.newInstance(), false, true, args); } }); return vi; }
From source file:tw.com.geminihsu.app01.fragment.Fragment_OrderFilter.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { MenuItem item = menu.add(Menu.NONE, ACTIONBAR_MENU_ITEM_FINISH, Menu.NONE, getString(R.string.btn_finish)); SpannableString spanString = new SpannableString(item.getTitle().toString()); spanString.setSpan(new ForegroundColorSpan(Color.WHITE), 0, spanString.length(), 0); //fix the color to white item.setTitle(spanString);/*from w w w . j a v a 2s .co m*/ item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); super.onCreateOptionsMenu(menu, inflater); }
From source file:com.example.textviewsample.MainActivityFragment.java
private void styleSourceCode() { TypefaceSpan codeSpan = new TypefaceSpan(getActivity(), "SourceCodePro-Regular"); TypefaceSpan codeSpan2 = new TypefaceSpan(getActivity(), "SourceCodePro-Bold", Typeface.BOLD); ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.MAGENTA); ForegroundColorSpan colorSpan2 = new ForegroundColorSpan(Color.BLUE); SpannableString title = new SpannableString(getString(R.string.code_sample)); title.setSpan(codeSpan, 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); title.setSpan(codeSpan2, 19, 23, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); title.setSpan(colorSpan, 4, 15, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); title.setSpan(colorSpan2, 19, 23, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); sourceCodeText.setText(title);// w ww . java 2s. c o m }
From source file:com.justwayward.reader.view.BookContentTextView.java
public void setText(String text) { int startIndex = 0; while (true) { int start = text.indexOf(""); int end = text.indexOf(""); if (start < 0 || end < 0) { append(text.substring(startIndex)); break; }//from w ww . j a v a2 s. c o m append(text.substring(startIndex, start)); SpannableString spanableInfo = new SpannableString(text.substring(start, end + 1)); spanableInfo.setSpan(new Clickable(spanableInfo.toString()), 0, end + 1 - start, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); append(spanableInfo); //setMovementMethod()??? setMovementMethod(LinkMovementMethod.getInstance()); text = text.substring(end + 1); LogUtils.e(spanableInfo.toString()); } }
From source file:io.vit.vitio.HomeActivity.java
public void setToolbarFormat(int pos, String t) { theme.refreshTheme();//from www . java2 s.c om if (!getSupportActionBar().isShowing()) { getSupportActionBar().show(); } String title = t; TypedArray colorres = theme.getToolbarColorTypedArray(); Log.d("setTooltheme", PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", "null")); getSupportActionBar() .setBackgroundDrawable(new ColorDrawable(getResources().getColor(colorres.getResourceId(pos, -1)))); SpannableString s = new SpannableString(title); s.setSpan(theme.getMyThemeTypeFaceSpan(), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); getSupportActionBar().setTitle(s); }
From source file:com.qiscus.sdk.ui.adapter.viewholder.QiscusBaseLinkViewHolder.java
private void clickify(String clickableText, ClickSpan.OnClickListener listener) { CharSequence text = messageTextView.getText(); String string = text.toString(); ClickSpan span = new ClickSpan(listener); int start = string.indexOf(clickableText); int end = start + clickableText.length(); if (start == -1) { return;/* w w w.j av a 2s. co m*/ } if (text instanceof Spannable) { ((Spannable) text).setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else { SpannableString s = SpannableString.valueOf(text); s.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); messageTextView.setText(s); } MovementMethod m = messageTextView.getMovementMethod(); if (m == null || !(m instanceof LinkMovementMethod)) { messageTextView.setMovementMethod(LinkMovementMethod.getInstance()); } }
From source file:ca.rmen.android.networkmonitor.app.about.AboutActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.about);//www . j av a2 s .c om String versionName; try { PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0); versionName = packageInfo.versionName; } catch (NameNotFoundException e) { // Should never happen throw new AssertionError(e); } ((TextView) findViewById(R.id.txtVersion)).setText(getString(R.string.app_name) + " v" + versionName); TextView tvLibraries = (TextView) findViewById(R.id.about_libraries); SpannableString content = new SpannableString(getString(R.string.about_libraries)); content.setSpan(new UnderlineSpan(), 0, content.length(), 0); tvLibraries.setText(content); getSupportActionBar().setDisplayHomeAsUpEnabled(true); }
From source file:io.vit.vitio.HomeActivity.java
public void setToolbarFormat(int pos) { theme.refreshTheme();/*from w w w .j a va 2s .co m*/ if (!getSupportActionBar().isShowing()) { getSupportActionBar().show(); } String title[] = getResources().getStringArray(R.array.drawer_list_titles); TypedArray colorres = theme.getToolbarColorTypedArray(); Log.d("setTooltheme", PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", "null")); getSupportActionBar() .setBackgroundDrawable(new ColorDrawable(getResources().getColor(colorres.getResourceId(pos, -1)))); SpannableString s = new SpannableString(title[pos]); s.setSpan(theme.getMyThemeTypeFaceSpan(), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); getSupportActionBar().setTitle(s); }