本文整理了Java中android.widget.TextView.setMovementMethod()
方法的一些代码示例,展示了TextView.setMovementMethod()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextView.setMovementMethod()
方法的具体详情如下:
包路径:android.widget.TextView
类名称:TextView
方法名:setMovementMethod
暂无
代码示例来源:origin: stackoverflow.com
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView link = (TextView)findViewById(R.id.link);
link.setText(
Html.fromHtml("<a href='myscheme://www.google.com'>link</a>"));
link.setMovementMethod(LinkMovementMethod.getInstance());
}
}
代码示例来源:origin: czy1121/update
tv.setMovementMethod(new ScrollingMovementMethod());
tv.setVerticalScrollBarEnabled(true);
tv.setTextSize(14);
tv.setText("您需要更新应用才能继续使用\n\n" + content);
dialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定", listener);
} else {
tv.setText(content);
dialog.setButton(DialogInterface.BUTTON_POSITIVE, "立即更新", listener);
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "以后再说", listener);
代码示例来源:origin: stackoverflow.com
TextView feedback = (TextView) findViewById(R.id.TextViewSendFeedback);
feedback.setText(Html.fromHtml("<a href=\"mailto:ask@me.it\">Send Feedback</a>"));
feedback.setMovementMethod(LinkMovementMethod.getInstance());
代码示例来源:origin: hidroh/materialistic
final TextView titleTextView = findViewById(android.R.id.text2);
if (story.isStoryType()) {
titleTextView.setText(story.getDisplayedTitle());
setTaskTitle(story.getDisplayedTitle());
if (!TextUtils.isEmpty(story.getSource())) {
TextView sourceTextView = findViewById(R.id.source);
sourceTextView.setText(story.getSource());
sourceTextView.setVisibility(View.VISIBLE);
getResources().getDimension(AppUtils.getThemedResId(this, R.attr.contentTextSize)));
CharSequence title = AppUtils.fromHtml(story.getDisplayedTitle(), true);
titleTextView.setText(title);
setTaskTitle(title);
postedTextView.setText(story.getDisplayedTime(this));
postedTextView.append(story.getDisplayedAuthor(this, true, 0));
postedTextView.setMovementMethod(LinkMovementMethod.getInstance());
switch (story.getType()) {
case Item.JOB_TYPE:
代码示例来源:origin: stackoverflow.com
TextView contactWeb1 = (TextView) findViewById(R.id.contactWeb1);
String desc = "<font color=\"red\"><a href='http://www.mysite.com/'>Visit my site</a></font>";
contactWeb1.setText(Html.fromHtml(desc));
contactWeb1.setMovementMethod(LinkMovementMethod.getInstance());
代码示例来源:origin: stackoverflow.com
String value = "<html>Visit my blog <a href=\"http://www.maxartists.com\">mysite</a> View <a href=\"sherif-activity://myactivity?author=sherif&nick=king\">myactivity</a> callback</html>";
TextView text = (TextView) findViewById(R.id.text);
text.setText(Html.fromHtml(value));
text.setMovementMethod(LinkMovementMethod.getInstance());
代码示例来源:origin: stackoverflow.com
TextView textView = (TextView) findViewById(R.id.TextBox);
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setText(Html.fromHtml(strText));
代码示例来源:origin: stackoverflow.com
TextView textView =(TextView)findViewById(R.id.textView);
textView.setClickable(true);
textView.setMovementMethod(LinkMovementMethod.getInstance());
String text = "<a href='http://www.google.com'> Google </a>";
textView.setText(Html.fromHtml(text));
代码示例来源:origin: stackoverflow.com
public static class MyOtherAlertDialog {
public static AlertDialog create(Context context) {
final TextView message = new TextView(context);
// i.e.: R.string.dialog_message =>
// "Test this dialog following the link to dtmilano.blogspot.com"
final SpannableString s =
new SpannableString(context.getText(R.string.dialog_message));
Linkify.addLinks(s, Linkify.WEB_URLS);
message.setText(s);
message.setMovementMethod(LinkMovementMethod.getInstance());
return new AlertDialog.Builder(context)
.setTitle(R.string.dialog_title)
.setCancelable(true)
.setIcon(android.R.drawable.ic_dialog_info)
.setPositiveButton(R.string.dialog_action_dismiss, null)
.setView(message)
.create();
}
}
代码示例来源:origin: stackoverflow.com
TextView tv1 = new TextView(this);
tv1.setLayoutParams(textOutLayoutParams);
tv1.setText(Html.fromHtml("<a href=\""+ l.getRightString() + "\">" + l.getLeftString() + "</a>"));
tv1.setClickable(true);
tv1.setMovementMethod (LinkMovementMethod.getInstance());
dialogLayout.addView(tv1);
代码示例来源:origin: stackoverflow.com
public static void clickify(TextView view, final String clickableText,
final ClickSpan.OnClickListener listener) {
CharSequence text = view.getText();
String string = text.toString();
ClickSpan span = new ClickSpan(listener);
int start = string.indexOf(clickableText);
int end = start + clickableText.length();
if (start == -1) return;
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);
view.setText(s);
}
MovementMethod m = view.getMovementMethod();
if ((m == null) || !(m instanceof LinkMovementMethod)) {
view.setMovementMethod(LinkMovementMethod.getInstance());
}
}
代码示例来源:origin: stackoverflow.com
TextView myTextView = new TextView(this);
String myString = "Some text [clickable]";
int i1 = myString.indexOf("[");
int i2 = myString.indexOf("]");
myTextView.setMovementMethod(LinkMovementMethod.getInstance());
myTextView.setText(myString, BufferType.SPANNABLE);
Spannable mySpannable = (Spannable)myTextView.getText();
ClickableSpan myClickableSpan = new ClickableSpan()
{
@Override
public void onClick(View widget) { /* do something */ }
};
mySpannable.setSpan(myClickableSpan, i1, i2 + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
代码示例来源:origin: stackoverflow.com
public class WordExtractTest extends Activity {
TextView tv1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv1 = (TextView)findViewById(R.id.tv1);
loadDoc();
}
private void loadDoc(){
String s = "";
for(int x=0;x<=100;x++){
s += "Line: "+String.valueOf(x)+"\n";
}
tv1.setMovementMethod(new ScrollingMovementMethod());
tv1.setText(s);
}
}
代码示例来源:origin: stackoverflow.com
protected void makeLinkClickable(SpannableStringBuilder strBuilder, final URLSpan span)
{
int start = strBuilder.getSpanStart(span);
int end = strBuilder.getSpanEnd(span);
int flags = strBuilder.getSpanFlags(span);
ClickableSpan clickable = new ClickableSpan() {
public void onClick(View view) {
// Do something with span.getURL() to handle the link click...
}
};
strBuilder.setSpan(clickable, start, end, flags);
strBuilder.removeSpan(span);
}
protected void setTextViewHTML(TextView text, String html)
{
CharSequence sequence = Html.fromHtml(html);
SpannableStringBuilder strBuilder = new SpannableStringBuilder(sequence);
URLSpan[] urls = strBuilder.getSpans(0, sequence.length(), URLSpan.class);
for(URLSpan span : urls) {
makeLinkClickable(strBuilder, span);
}
text.setText(strBuilder);
text.setMovementMethod(LinkMovementMethod.getInstance());
}
代码示例来源:origin: Cleveroad/AdaptiveTableLayout
@Override
public void onViewCreated(@NonNull 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, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
createDemoFile();
}
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
};
ss.setSpan(clickableSpan, START_CHARACTER, END_CHARACTER, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
tvPickFile.setText(ss);
tvPickFile.setMovementMethod(LinkMovementMethod.getInstance());
tvPickFile.setHighlightColor(Color.TRANSPARENT);
}
代码示例来源:origin: stackoverflow.com
_tv.setMovementMethod(LinkMovementMethod.getInstance());
_tv.setText(addClickablePart(sentence), BufferType.SPANNABLE);
代码示例来源:origin: DreaminginCodeZH/MaterialProgressBar
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about_activity);
ButterKnife.bind(this);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
String version = getString(R.string.about_version_format, BuildConfig.VERSION_NAME);
mVersionText.setText(version);
mGithubText.setMovementMethod(LinkMovementMethod.getInstance());
}
代码示例来源:origin: bluelinelabs/Conductor
@Override
public void onViewBound(@NonNull View view) {
super.onViewBound(view);
tvTitle.setText(getArgs().getCharSequence(KEY_TITLE));
tvDescription.setText(getArgs().getCharSequence(KEY_DESCRIPTION));
tvDescription.setMovementMethod(LinkMovementMethod.getInstance());
}
代码示例来源:origin: seven332/EhViewer
@Nullable
@Override
public View onCreateView2(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.scene_analytics, container, false);
mReject = ViewUtils.$$(view, R.id.reject);
mAccept = ViewUtils.$$(view, R.id.accept);
TextView text = (TextView) ViewUtils.$$(view, R.id.text);
text.setText(Html.fromHtml(getString(R.string.analytics_explain)));
text.setMovementMethod(LinkMovementMethod2.getInstance());
mReject.setOnClickListener(this);
mAccept.setOnClickListener(this);
return view;
}
代码示例来源:origin: nickbutcher/plaid
/**
* Work around some 'features' of TextView and URLSpans. i.e. vanilla URLSpans do not react to
* touch so we replace them with our own {@link TouchableUrlSpan}
* & {@link LinkTouchMovementMethod} to fix this.
* <p/>
* Setting a custom MovementMethod on a TextView also alters touch handling (see
* TextView#fixFocusableAndClickableSettings) so we need to correct this.
*/
public static void setTextWithNiceLinks(TextView textView, CharSequence input) {
textView.setText(input);
textView.setMovementMethod(LinkTouchMovementMethod.getInstance());
textView.setFocusable(false);
textView.setClickable(false);
textView.setLongClickable(false);
}
内容来源于网络,如有侵权,请联系作者删除!