當前位置: 首頁>>代碼示例>>Java>>正文


Java ClickableSpan類代碼示例

本文整理匯總了Java中android.text.style.ClickableSpan的典型用法代碼示例。如果您正苦於以下問題:Java ClickableSpan類的具體用法?Java ClickableSpan怎麽用?Java ClickableSpan使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ClickableSpan類屬於android.text.style包,在下文中一共展示了ClickableSpan類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onViewCreated

import android.text.style.ClickableSpan; //導入依賴的package包/類
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    SpannableString ss = new SpannableString(getString(R.string.pick_csv_or_demo_file));
    ClickableSpan clickableSpan = new ClickableSpan() {
        @Override
        public void onClick(View textView) {
            if (PermissionHelper.checkOrRequest(CsvPickerFragment.this, REQUEST_CODE_PERMISSION_READ_EXTERNAL_STORAGE_DEMO,
                    Manifest.permission.READ_EXTERNAL_STORAGE)) {
                createDemoFile();
            }
        }

        @Override
        public void updateDrawState(TextPaint ds) {
            super.updateDrawState(ds);
            ds.setUnderlineText(false);
        }
    };
    ss.setSpan(clickableSpan, 32, 36, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    tvPickFile.setText(ss);
    tvPickFile.setMovementMethod(LinkMovementMethod.getInstance());
    tvPickFile.setHighlightColor(Color.TRANSPARENT);
}
 
開發者ID:Cleveroad,項目名稱:AdaptiveTableLayout,代碼行數:26,代碼來源:CsvPickerFragment.java

示例2: setHtmlWithLinkClickHandler

import android.text.style.ClickableSpan; //導入依賴的package包/類
public static void setHtmlWithLinkClickHandler(TextView tv, String html,
                                        Action1<String> linkClickHandler) {
    CharSequence sequence = Html.fromHtml(html);
    SpannableStringBuilder strBuilder = new SpannableStringBuilder(sequence);
    URLSpan[] urls = strBuilder.getSpans(0, sequence.length(), URLSpan.class);
    for (URLSpan span : urls) {
        int start = strBuilder.getSpanStart(span);
        int end = strBuilder.getSpanEnd(span);
        int flags = strBuilder.getSpanFlags(span);
        ClickableSpan clickable = new ClickableSpan() {
            public void onClick(View view) {
                linkClickHandler.call(span.getURL());
            }
        };
        strBuilder.setSpan(clickable, start, end, flags);
        strBuilder.removeSpan(span);
    }
    tv.setText(strBuilder);
    tv.setMovementMethod(LinkMovementMethod.getInstance());
}
 
開發者ID:TryGhost,項目名稱:Ghost-Android,代碼行數:21,代碼來源:AppUtils.java

示例3: changeToLight

import android.text.style.ClickableSpan; //導入依賴的package包/類
/**
 * 解析URL和電話號碼並高亮顯示
 */
private SpannableString changeToLight(String str) {
    SpannableString string = new SpannableString(str);
    for (Pattern p : mPatterns) {
        Matcher m = p.matcher(string);
        while (m.find()) {
            int start = m.start();
            int end = m.end();
            string.setSpan(new ClickableSpan() {
                @Override
                public void updateDrawState(TextPaint ds) {
                    super.updateDrawState(ds);
                    ds.setColor(getColors(R.color.color_theme));
                }

                @Override
                public void onClick(View widget) {

                }

            }, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    return string;
}
 
開發者ID:jpaijh,項目名稱:TYT,代碼行數:28,代碼來源:MessageCenterActivity.java

示例4: genTimeAndReplyText

import android.text.style.ClickableSpan; //導入依賴的package包/類
private Spannable genTimeAndReplyText(final Comment comment) {
    String time = AppTextUtils.getDateFromUnixTime(comment.getDate());
    if (comment.getReplyToUser() == 0) {
        return Spannable.Factory.getInstance().newSpannable(time);
    }

    String commentText = context.getString(R.string.comment).toLowerCase();
    String target = context.getString(R.string.in_response_to, time, commentText);

    int start = target.indexOf(commentText);

    Spannable spannable = Spannable.Factory.getInstance().newSpannable(target);
    ClickableSpan span = new ClickableSpan() {
        @Override
        public void onClick(View widget) {
            onReplyClick(comment.getReplyToUser(), comment.getReplyToComment());
        }
    };

    spannable.setSpan(span, start, target.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannable;
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:23,代碼來源:CommentsAdapter.java

示例5: makeLinksClickable

import android.text.style.ClickableSpan; //導入依賴的package包/類
public static void makeLinksClickable(TextView v) {
	SpannableStringBuilder ssb = new SpannableStringBuilder(v.getText());
	URLSpan[] spans = ssb.getSpans(0, ssb.length(), URLSpan.class);
	for (URLSpan span : spans) {
		int start = ssb.getSpanStart(span);
		int end = ssb.getSpanEnd(span);
		final String url = span.getURL();
		ssb.removeSpan(span);
		ClickableSpan cSpan = new ClickableSpan() {
			@Override
			public void onClick(View v2) {
				LinkDialogFragment f = LinkDialogFragment.newInstance(url);
				FragmentManager fm = ((AppCompatActivity) v2.getContext())
						.getSupportFragmentManager();
				f.show(fm, f.getUniqueTag());
			}
		};
		ssb.setSpan(cSpan, start, end, 0);
	}
	v.setText(ssb);
	v.setMovementMethod(ArticleMovementMethod.getInstance());
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:23,代碼來源:UiUtils.java

示例6: getClickableSpan

import android.text.style.ClickableSpan; //導入依賴的package包/類
/**
     * 獲取超鏈接字段
     * @return 超鏈接字符串
     */
    private SpannableString getClickableSpan(String aStr) {
        int startIndex = aStr.indexOf(mAuthorName);
        int endIndex = startIndex + mAuthorName.length();
        SpannableString spannableString = new SpannableString(aStr);
        //設置下劃線文字
//        spannableString.setSpan(new UnderlineSpan(), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        //設置文字的單擊事件
        spannableString.setSpan(new ClickableSpan() {
            @Override
            public void onClick(View widget) {
                Uri uri = Uri.parse(mExtLink);
                Context context = widget.getContext();
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
                context.startActivity(intent);
            }
        }, startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        //設置文字的前景色
        spannableString.setSpan(new ForegroundColorSpan(ThemeStyle.Accent), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        return spannableString;
    }
 
開發者ID:mainh,項目名稱:MainCalendar,代碼行數:27,代碼來源:AboutActivity.java

示例7: prepareMainMessageString

import android.text.style.ClickableSpan; //導入依賴的package包/類
private CharSequence prepareMainMessageString(final PermissionDialogDelegate delegate) {
    SpannableStringBuilder fullString = new SpannableStringBuilder();

    String messageText = delegate.getMessageText();
    String linkText = delegate.getLinkText();
    if (!TextUtils.isEmpty(messageText)) fullString.append(messageText);

    // If the linkText exists, then wrap it in a clickable span and concatenate it with the main
    // dialog message.
    if (!TextUtils.isEmpty(linkText)) {
        if (fullString.length() > 0) fullString.append(" ");
        int spanStart = fullString.length();

        fullString.append(linkText);
        fullString.setSpan(new ClickableSpan() {
            @Override
            public void onClick(View view) {
                mDecision = NOT_DECIDED;
                delegate.onLinkClicked();
                if (mDialog != null) mDialog.dismiss();
            }
        }, spanStart, fullString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    return fullString;
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:27,代碼來源:PermissionDialogController.java

示例8: getDescriptionText

import android.text.style.ClickableSpan; //導入依賴的package包/類
private SpannableString getDescriptionText() {
    return SpanApplier.applySpans(
            getString(R.string.physical_web_optin_description),
            new SpanInfo("<learnmore>", "</learnmore>", new ClickableSpan() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(Intent.ACTION_VIEW,
                            Uri.parse(PHYSICAL_WEB_LEARN_MORE_URL));
                    // Add the SESSION extra to indicate we want a Chrome custom tab. This
                    // allows the help page to open in the same task as the opt-in activity so
                    // they can share a back stack.
                    String session = null;
                    intent.putExtra(EXTRA_CUSTOM_TABS_SESSION, session);
                    PhysicalWebOptInActivity.this.startActivity(intent);
                }

                @Override
                public void updateDrawState(TextPaint ds) {
                    // Color links but do not underline them.
                    ds.setColor(ds.linkColor);
                }
            }));
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:24,代碼來源:PhysicalWebOptInActivity.java

示例9: getResetText

import android.text.style.ClickableSpan; //導入依賴的package包/類
private SpannableString getResetText() {
    final Context context = getActivity();
    return SpanApplier.applySpans(
            context.getString(R.string.sync_passphrase_encryption_reset_instructions),
            new SpanInfo("<resetlink>", "</resetlink>", new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    Uri syncDashboardUrl = Uri.parse(
                            context.getText(R.string.sync_dashboard_url).toString());
                    Intent intent = new Intent(Intent.ACTION_VIEW, syncDashboardUrl);
                    intent.setPackage(BuildInfo.getPackageName(context));
                    IntentUtils.safePutBinderExtra(
                            intent, CustomTabsIntent.EXTRA_SESSION, null);
                    context.startActivity(intent);
                }
            }));
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:18,代碼來源:PassphraseTypeDialogFragment.java

示例10: getResetText

import android.text.style.ClickableSpan; //導入依賴的package包/類
private SpannableString getResetText() {
    final Context context = getActivity();
    return SpanApplier.applySpans(
            context.getString(R.string.sync_passphrase_reset_instructions),
            new SpanInfo("<resetlink>", "</resetlink>", new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    recordPassphraseDialogDismissal(PASSPHRASE_DIALOG_RESET_LINK);
                    Uri syncDashboardUrl = Uri.parse(
                            context.getText(R.string.sync_dashboard_url).toString());
                    Intent intent = new Intent(Intent.ACTION_VIEW, syncDashboardUrl);
                    intent.setPackage(BuildInfo.getPackageName(context));
                    IntentUtils.safePutBinderExtra(
                            intent, CustomTabsIntent.EXTRA_SESSION, null);
                    context.startActivity(intent);
                }
            }));
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:19,代碼來源:PassphraseDialogFragment.java

示例11: createContent

import android.text.style.ClickableSpan; //導入依賴的package包/類
@Override
public void createContent(InfoBarLayout layout) {
    super.createContent(layout);
    if (mTitleLinkRangeStart != 0 && mTitleLinkRangeEnd != 0) {
        SpannableString title = new SpannableString(mTitle);
        title.setSpan(new ClickableSpan() {
            @Override
            public void onClick(View view) {
                onLinkClicked();
            }
        }, mTitleLinkRangeStart, mTitleLinkRangeEnd, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        layout.setMessage(title);
    }

    InfoBarControlLayout controlLayout = layout.addControlLayout();
    if (mUsernames.length > 1) {
        InfoBarArrayAdapter<String> usernamesAdapter =
                new InfoBarArrayAdapter<String>(getContext(), mUsernames);
        mUsernamesSpinner = controlLayout.addSpinner(
                R.id.password_infobar_accounts_spinner, usernamesAdapter);
    } else {
        controlLayout.addDescription(mUsernames[0]);
    }
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:25,代碼來源:UpdatePasswordInfoBar.java

示例12: getOfflinePageMessageText

import android.text.style.ClickableSpan; //導入依賴的package包/類
/**
 * Gets the infobar text for offline page downloads.
 * @param context Context to be used.
 * @param template Template of the text to be displayed.
 */
private CharSequence getOfflinePageMessageText(final Context context, final String template) {
    return getMessageText(template, mFilePath, new ClickableSpan() {
        @Override
        public void onClick(View view) {
            // TODO(qinmin): open the offline page on local storage instead of opening the url.
            // However, there could be multiple stored offline pages for the same url, need to
            // figure out which one to use.
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(mPageUrl));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setPackage(context.getPackageName());
            context.startActivity(intent);
        }
    });
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:21,代碼來源:DuplicateDownloadInfoBar.java

示例13: prepareMainMessageString

import android.text.style.ClickableSpan; //導入依賴的package包/類
/**
 * Prepares text to be displayed as the infobar's main message, including setting up a
 * clickable link if the infobar requires it.
 */
private CharSequence prepareMainMessageString() {
    SpannableStringBuilder fullString = new SpannableStringBuilder();

    if (mMessageMainText != null) fullString.append(mMessageMainText);

    // Concatenate the text to display for the link and make it clickable.
    if (!TextUtils.isEmpty(mMessageLinkText)) {
        if (fullString.length() > 0) fullString.append(" ");
        int spanStart = fullString.length();

        fullString.append(mMessageLinkText);
        fullString.setSpan(new ClickableSpan() {
            @Override
            public void onClick(View view) {
                mInfoBarView.onLinkClicked();
            }
        }, spanStart, fullString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    return fullString;
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:26,代碼來源:InfoBarLayout.java

示例14: createContent

import android.text.style.ClickableSpan; //導入依賴的package包/類
@Override
public void createContent(InfoBarLayout layout) {
    super.createContent(layout);
    InfoBarControlLayout control = layout.addControlLayout();
    for (int i = 0; i < mCardDetails.size(); i++) {
        CardDetail detail = mCardDetails.get(i);
        control.addIcon(detail.issuerIconDrawableId, 0, detail.label, detail.subLabel);
    }

    for (LegalMessageLine line : mLegalMessageLines) {
        SpannableString text = new SpannableString(line.text);
        for (final LegalMessageLine.Link link : line.links) {
            text.setSpan(new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    nativeOnLegalMessageLinkClicked(mNativeAutofillSaveCardInfoBar, link.url);
                }
            }, link.start, link.end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        }
        control.addDescription(text);
    }
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:23,代碼來源:AutofillSaveCardInfoBar.java

示例15: createContent

import android.text.style.ClickableSpan; //導入依賴的package包/類
@Override
public void createContent(InfoBarLayout layout) {
    super.createContent(layout);
    SpannableString message = new SpannableString(mMessageText);
    message.setSpan(
            new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    onLinkClicked();
                }

                @Override
                public void updateDrawState(TextPaint ds) {
                    super.updateDrawState(ds);
                    ds.setUnderlineText(false);
                }
            }, mInlineLinkRangeStart, mInlineLinkRangeEnd, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    layout.setMessage(message);
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:20,代碼來源:SearchGeolocationDisclosureInfoBar.java


注:本文中的android.text.style.ClickableSpan類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。