我使用Markwon库,遇到了问题。它无法识别链接。我输入的链接为[name](link)
,它仅显示名称,不突出显示该名称,也不响应该名称的点击。如何解决此错误?
我的Gradle条目:
implementation "ru.noties:markwon:2.0.1"
implementation "ru.noties:markwon-image-loader:2.0.1"
implementation "ru.noties:markwon-syntax-highlight:2.0.1"
implementation "ru.noties:markwon-view:2.0.1"
配置:
public SpannableConfiguration getAboutTextConfig() {
ImageSizeResolverFitWidth imgSizeResolver = new ImageSizeResolverFitWidth();
return SpannableConfiguration.builder(this.context)
.asyncDrawableLoader(AsyncDrawableLoader.create())
.imageSizeResolver(imgSizeResolver)
.build();
}
我也尝试过这个:
在代码中:
act_txt.setMovementMethod(LinkMovementMethod.getInstance());
在布局中:
<TextView
android:id="@+id/act_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:autoLink="web"
android:focusable="true"
android:fontFamily="@font/roboto_regular"
android:letterSpacing="0.03"
android:lineSpacingExtra="12sp"
android:linksClickable="true"
android:paddingBottom="30dp"
android:textColor="@color/titleTextColor"
android:textSize="16sp"
android:textStyle="normal" />
并覆盖LinkResolver
和UrlProc
class LinkResolver implements LinkSpan.Resolver {
@Override
public void resolve(View view, @NonNull String link) {
final Uri uri = Uri.parse(link);
final Context context = view.getContext();
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
try {
context.startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.w("LinkResolverDef", "Actvity was not found for intent, " + intent.toString());
}
}
}
@SuppressWarnings("WeakerAccess")
public class UrlProcessorRelative implements UrlProcessor {
private final URL base;
public UrlProcessorRelative(@NonNull String base) {
this.base = obtain(base);
}
@NonNull
@Override
public String process(@NonNull String destination) {
String out = destination;
if (base != null) {
try {
final URL u = new URL(base, destination);
out = u.toString();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
return out;
}
@Nullable
private URL obtain(String base) {
try {
return new URL(base);
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
}
}
}
答案 0 :(得分:0)
很高兴您解决了问题。对于其他追逐这只兔子的人,在我的TextView上设置LinkMovementMethod对我来说很有效。
myTextView.movementMethod = LinkMovementMethod.getInstance()