Markwon不处理链接

问题描述 投票:1回答:1

我使用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" />

并覆盖LinkResolverUrlProc

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;
        }
    }
}
java android markdown
1个回答
0
投票

很高兴你解决了你的问题。对于其他追逐这只兔子的人来说,在我的TextView上设置LinkMovementMethod对我有用。

myTextView.movementMethod = LinkMovementMethod.getInstance()
© www.soinside.com 2019 - 2024. All rights reserved.