本文整理汇总了Java中android.text.method.LinkMovementMethod类的典型用法代码示例。如果您正苦于以下问题:Java LinkMovementMethod类的具体用法?Java LinkMovementMethod怎么用?Java LinkMovementMethod使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LinkMovementMethod类属于android.text.method包,在下文中一共展示了LinkMovementMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createAboutDialog
import android.text.method.LinkMovementMethod; //导入依赖的package包/类
/**
* @brief Shows the dialog to indicate about info
* @return The new dialog
* @details Shows the dialog to indicate about info
*/
private Dialog createAboutDialog()
{
//necesario para poder clicar en los links
final TextView message = new TextView(this);
final SpannableString s =
new SpannableString(this.getText(R.string.about_message));
Linkify.addLinks(s, Linkify.WEB_URLS);
message.setText(s);
message.setMovementMethod(LinkMovementMethod.getInstance());
return new AlertDialog.Builder(this)
.setTitle(R.string.about_title)
.setView(message)
.setPositiveButton(R.string.about_ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Auto-generated method stub
}
}
)
.show();
}
示例2: setHtmlWithLinkClickHandler
import android.text.method.LinkMovementMethod; //导入依赖的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());
}
示例3: onCreate
import android.text.method.LinkMovementMethod; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.NoActionBar);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
ButterKnife.bind(this);
toolbar.setTitleTextColor(ContextCompat.getColor(this, R.color.white));
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_return);
toolbar.setNavigationOnClickListener(v -> onBackPressed());
title.setMovementMethod(LinkMovementMethod.getInstance());
}
示例4: onCreate
import android.text.method.LinkMovementMethod; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
// about_page_textview has links specified by putting <a> tags in the string
// resource. By default these links will appear but not
// respond to user input. To make them active, you need to
// call setMovementMethod() on the TextView object.
TextView aboutPageText = (TextView) findViewById(R.id.about_page_textview);
aboutPageText.setMovementMethod(LinkMovementMethod.getInstance());
// This makes the image clickable
ImageView img = (ImageView)findViewById(R.id.about_page_image);
img.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse("http://serc.strathmore.edu/"));
startActivity(intent);
}
});
}
示例5: setText
import android.text.method.LinkMovementMethod; //导入依赖的package包/类
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;
}
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());
}
}
示例6: onCreateDialog
import android.text.method.LinkMovementMethod; //导入依赖的package包/类
@SuppressLint("InflateParams")
@Override
public AlertDialog onCreateDialog(Bundle savedInstanceState) {
View dialogView = LayoutInflater.from(getActivity())
.inflate(R.layout.dialog_message, null);
TextView messageView = (TextView) dialogView.findViewById(R.id.message);
messageView.setMovementMethod(LinkMovementMethod.getInstance());
messageView.setText(Html.fromHtml(getArguments().getString(ARG_MESSAGE)));
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppTheme_AlertDialog);
builder.setTitle(getArguments().getString(ARG_TITLE))
.setIcon(getArguments().getInt(ARG_ICON))
.setView(dialogView)
.setPositiveButton(R.string.OK, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
return builder.create();
}
示例7: convert
import android.text.method.LinkMovementMethod; //导入依赖的package包/类
@Override
protected void convert(BaseViewHolder helper, Status item) {
helper.addOnClickListener(R.id.tweetText);
switch (helper.getLayoutPosition()%
3){
case 0:
helper.setImageResource(R.id.img,R.mipmap.animation_img1);
break;
case 1:
helper.setImageResource(R.id.img,R.mipmap.animation_img2);
break;
case 2:
helper.setImageResource(R.id.img,R.mipmap.animation_img3);
break;
}
helper.setText(R.id.tweetName,"Hoteis in Rio de Janeiro");
String msg="\"He was one of Australia's most of distinguished artistes, renowned for his portraits\"";
( (TextView)helper.getView(R.id.tweetText)).setText(SpannableStringUtils.getBuilder(msg).append("landscapes and nedes").setClickSpan(clickableSpan).create());
( (TextView)helper.getView(R.id.tweetText)).setMovementMethod(LinkMovementMethod.getInstance());
}
示例8: onStart
import android.text.method.LinkMovementMethod; //导入依赖的package包/类
@Override
public void onStart() {
super.onStart();
mState.setOnClickListener(this);
if(negative == 0)
mNegative.setVisibility(View.GONE);
else {
mNegative.setOnClickListener(this);
mNegative.setText(negative);
}
if(positive == 0)
mPositive.setVisibility(View.GONE);
else {
mPositive.setOnClickListener(this);
mPositive.setText(positive);
}
mTitle.setText(title);
mText.setMovementMethod(LinkMovementMethod.getInstance());
mText.setText(Html.fromHtml(getString(text)));
if(bottomSheetBehavior.getState() != BottomSheetBehavior.STATE_EXPANDED)
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
示例9: createSadTabView
import android.text.method.LinkMovementMethod; //导入依赖的package包/类
/**
* @param context Context of the resulting Sad Tab view.
* @param suggestionAction Action to be executed when user clicks "try these suggestions".
* @param reloadButtonAction Action to be executed when Reload button is pressed.
* (e.g., refreshing the page)
* @return A "Sad Tab" view instance which is used in place of a crashed renderer.
*/
public static View createSadTabView(
Context context, final OnClickListener suggestionAction,
OnClickListener reloadButtonAction) {
// Inflate Sad tab and initialize.
LayoutInflater inflater = (LayoutInflater) context.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
View sadTabView = inflater.inflate(R.layout.sad_tab, null);
TextView messageText = (TextView) sadTabView.findViewById(R.id.sad_tab_message);
messageText.setText(getHelpMessage(context, suggestionAction));
messageText.setMovementMethod(LinkMovementMethod.getInstance());
Button reloadButton = (Button) sadTabView.findViewById(R.id.sad_tab_reload_button);
reloadButton.setOnClickListener(reloadButtonAction);
return sadTabView;
}
示例10: displayShareInfo
import android.text.method.LinkMovementMethod; //导入依赖的package包/类
private void displayShareInfo(final Share share)
{
final TextView textView = new TextView(this);
textView.setPadding(5, 5, 5, 5);
final Spannable message = new SpannableString("Owner: " + share.getUsername() +
"\nComments: " + ((share.getDescription() == null) ? "" : share.getDescription()) +
"\nURL: " + share.getUrl() +
"\nEntry Count: " + share.getEntries().size() +
"\nVisit Count: " + share.getVisitCount() +
((share.getCreated() == null) ? "" : ("\nCreation Date: " + share.getCreated().replace('T', ' '))) +
((share.getLastVisited() == null) ? "" : ("\nLast Visited Date: " + share.getLastVisited().replace('T', ' '))) +
((share.getExpires() == null) ? "" : ("\nExpiration Date: " + share.getExpires().replace('T', ' '))));
Linkify.addLinks(message, Linkify.WEB_URLS);
textView.setText(message);
textView.setMovementMethod(LinkMovementMethod.getInstance());
new AlertDialog.Builder(this).setTitle("Share Details").setCancelable(true).setIcon(android.R.drawable.ic_dialog_info).setView(textView).show();
}
示例11: onCreate
import android.text.method.LinkMovementMethod; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
findViewById(R.id.btn_play_again).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PrefManager prefManager = new PrefManager(getApplicationContext());
prefManager.setFirstTimeLaunch(true);
startActivity(new Intent(MainActivity.this, WelcomeActivity.class));
finish();
}
});
TextView textView =(TextView)findViewById(R.id.textView);
textView.setClickable(true);
textView.setMovementMethod(LinkMovementMethod.getInstance());
String text = "<a href='https://github.com/Kvaibhav01/IntroApp'> Star or Fork this project on GitHub </a>";
textView.setText(Html.fromHtml(text));
}
示例12: onClickURL
import android.text.method.LinkMovementMethod; //导入依赖的package包/类
private void onClickURL(){
MovementMethod contributors_descMovementMethod = contributors_desc.getMovementMethod();
if ((contributors_descMovementMethod == null) || !(contributors_descMovementMethod instanceof LinkMovementMethod)) {
if (contributors_desc.getLinksClickable()) {
contributors_desc.setMovementMethod(LinkMovementMethod.getInstance());
}
}
MovementMethod app_report_issues_descMovementMethod = app_report_issues_desc.getMovementMethod();
if ((app_report_issues_descMovementMethod == null) || !(app_report_issues_descMovementMethod instanceof LinkMovementMethod)) {
if (app_report_issues_desc.getLinksClickable()) {
app_report_issues_desc.setMovementMethod(LinkMovementMethod.getInstance());
}
}
MovementMethod app_license_info_descMovementMethod = app_license_info_desc.getMovementMethod();
if ((app_license_info_descMovementMethod == null) || !(app_license_info_descMovementMethod instanceof LinkMovementMethod)) {
if (app_license_info_desc.getLinksClickable()) {
app_license_info_desc.setMovementMethod(LinkMovementMethod.getInstance());
}
}
}
示例13: displayVideoInfo
import android.text.method.LinkMovementMethod; //导入依赖的package包/类
@Override
public void displayVideoInfo(Video video) {
if(nonNull(mRootView)){
mRootView.findViewById(R.id.content).setVisibility(View.VISIBLE);
mRootView.findViewById(R.id.loading_root).setVisibility(View.GONE);
}
safelySetText(mTitleText, video.getTitle());
if(nonNull(mSubtitleText)){
Spannable subtitle = OwnerLinkSpanFactory.withSpans(video.getDescription(), true, false, ownerLinkAdapter);
mSubtitleText.setText(subtitle, TextView.BufferType.SPANNABLE);
mSubtitleText.setMovementMethod(LinkMovementMethod.getInstance());
}
String imageUrl = video.getMaxResolutionPhoto();
if (nonEmpty(imageUrl) && nonNull(mPreviewImage)) {
PicassoInstance.with()
.load(imageUrl)
.into(mPreviewImage);
}
}
示例14: onCustomiseDialog
import android.text.method.LinkMovementMethod; //导入依赖的package包/类
@Override
protected @NonNull DynamicDialog onCustomiseDialog(@NonNull DynamicDialog alertDialog,
@Nullable Bundle savedInstanceState) {
View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_about,
new LinearLayout(getContext()), false);
TextView message = view.findViewById(R.id.dialog_about_text);
message.setText(Html.fromHtml(getString(R.string.about_content)
.replace("\n", "<br/>")));
message.setTextSize(TypedValue.COMPLEX_UNIT_SP, TEXT_SIZE);
message.setLineSpacing(0f, 1.2f);
message.setMovementMethod(LinkMovementMethod.getInstance());
message.setLinkTextColor(ContextCompat.getColor(getContext(), R.color.colorPrimary));
alertDialog.setView(view);
return alertDialog;
}
示例15: displayPost
import android.text.method.LinkMovementMethod; //导入依赖的package包/类
public void displayPost(CharSequence title, CharSequence author, CharSequence content,
String link) {
View v = LayoutInflater.from(this).inflate(R.layout.post_row, mainlist, false);
((TextView) v.findViewById(R.id.title))
.setText(title);
((TextView) v.findViewById(R.id.author)).setText(author);
if (content != null || link != null) {
((TextView) v.findViewById(R.id.content))
.setMovementMethod(LinkMovementMethod.getInstance());
v.findViewById(R.id.content).setVisibility(View.VISIBLE);
if (content != null) {
((TextView) v.findViewById(R.id.content)).setText(content);
} else if (link != null) {
((TextView) v.findViewById(R.id.content))
.setText(Util.linkToSpan(link));
}
}
mainlist.addView(v);
}