List of usage examples for android.text SpannableString length
int length();
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.jav a 2 s. com*/ }
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);// ww w.ja v a 2s .co m item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); super.onCreateOptionsMenu(menu, inflater); }
From source file:com.android.screenspeak.menurules.RuleSpannables.java
@Override public boolean accept(Context context, AccessibilityNodeInfoCompat node) { final CharSequence text = node.getText(); if (!TextUtils.isEmpty(text) && (text instanceof SpannableString)) { final SpannableString spannable = (SpannableString) node.getText(); final URLSpan[] urlSpans = spannable.getSpans(0, spannable.length(), URLSpan.class); if (urlSpans.length > 0) { return true; }//from www .j a v a 2s .c om } return false; }
From source file:ca.rmen.android.networkmonitor.app.about.AboutActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.about);/* w w w .j a va 2 s .c o m*/ 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, String t) { theme.refreshTheme();//from www . ja va 2 s . c o m 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:io.vit.vitio.HomeActivity.java
public void setToolbarFormat(int pos) { theme.refreshTheme();//from w w w .j a v a 2 s. c o 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); }
From source file:com.groupme.sdk.activity.PinEntryActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pinentry); TextView pinEntryInstructions = (TextView) findViewById(R.id.pin_entry_instructions); pinEntryInstructions//from ww w .j ava 2 s .com .setText(getString(R.string.pin_entry_instructions, getIntent().getStringExtra("phone_number"))); mNameEntry = (EditText) findViewById(R.id.name_entry); mPinEntry = (EditText) findViewById(R.id.pin_entry); mAlternateButton = (Button) findViewById(R.id.not_number_button); SpannableString str = new SpannableString(getString(R.string.link_not_number)); str.setSpan(new UnderlineSpan(), 0, str.length(), 0); mAlternateButton.setText(str); }
From source file:com.flowzr.activity.EntityListActivity.java
public void setMyTitle(String t) { SpannableString s = new SpannableString(t); s.setSpan(new TypefaceSpan("sans-serif"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); getSupportActionBar().setTitle(s);//from www . j a v a2 s .co m }
From source file:com.android.screenspeak.menurules.RuleSpannables.java
@Override public List<ContextMenuItem> getMenuItemsForNode(ScreenSpeakService service, ContextMenuItemBuilder menuItemBuilder, AccessibilityNodeInfoCompat node) { final SpannableString spannable = (SpannableString) node.getText(); final URLSpan[] urlSpans = spannable.getSpans(0, spannable.length(), URLSpan.class); final LinkedList<ContextMenuItem> result = new LinkedList<>(); if ((urlSpans == null) || (urlSpans.length == 0)) { return result; }/*from ww w . j a v a 2 s. co m*/ for (int i = 0; i < urlSpans.length; i++) { final URLSpan urlSpan = urlSpans[i]; final String url = urlSpan.getURL(); final int start = spannable.getSpanStart(urlSpan); final int end = spannable.getSpanEnd(urlSpan); final CharSequence label = spannable.subSequence(start, end); if (TextUtils.isEmpty(url) || TextUtils.isEmpty(label)) { continue; } final Uri uri = Uri.parse(url); if (uri.isRelative()) { // Generally, only absolute URIs are resolvable to an activity continue; } final ContextMenuItem item = menuItemBuilder.createMenuItem(service, Menu.NONE, i, Menu.NONE, label); item.setOnMenuItemClickListener(new SpannableMenuClickListener(service, uri)); result.add(item); } return result; }
From source file:com.senior.fragments.ArticleContent.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //Obtains each articleView = inflater.inflate(R.layout.articles_fragment, container, false); TextView title = (TextView) articleView.findViewById(R.id.title); progress = (ProgressBar) articleView.findViewById(R.id.progress); SpannableString NewTitle = new SpannableString(articleTitle); //Sets the options for display NewTitle.setSpan(new UnderlineSpan(), 0, NewTitle.length(), 0); title.setText(NewTitle);/*from ww w .j av a 2 s . co m*/ reloadButton = (Button) articleView.findViewById(R.id.refresh); reloadButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { refreshArticle(); } }); return articleView; }