logo
down
shadow

Html.fromHtml on Nougat doesn't call custom HtmlHandler


Html.fromHtml on Nougat doesn't call custom HtmlHandler

By : Aadya Sharan
Date : November 20 2020, 11:01 PM
help you fix your problem Html.fromHtml() will only invoke your TagHandler for HTML tags that fromHtml() does not recognize. In your sample HTML, you have:

code :


Share : facebook icon twitter icon
Using Html.fromHtml to set custom Typeface

Using Html.fromHtml to set custom Typeface


By : Gregory Kinelap
Date : March 29 2020, 07:55 AM
should help you out Outdated. See other answers.
No, there's no way to do so. You can take a look at the Html implementation. As you will see, the font tag supports size and color only.
Spanned as from Html.fromHtml, but with custom ClickableSpan for custom scheme

Spanned as from Html.fromHtml, but with custom ClickableSpan for custom scheme


By : robin
Date : March 29 2020, 07:55 AM
wish helps you Option 1 is probably most straightforward and most of the hard work for it has already been done before. You've got the general idea correct: after the HTML has been processed, you can request all the generated URLSpan instances and loop through them. You can then replace it with a customized clickable span to get full controls over any of the span clicks.
In the example below, I'm just replacing every URLSpan with a simple extension of that class that takes the original url (actually, I should probably say 'uri') and replace its scheme part. I've left the actual onClick() logic unimplemented, but I'll leave that up to your imagination.
code :
SpannableStringBuilder builder = ...
URLSpan[] spans = builder .getSpans(0, builder .length(), URLSpan.class);
for (URLSpan span : spans) {
    int start = builder .getSpanStart(span);
    int end = builder .getSpanEnd(span);
    s.removeSpan(span);
    span = new CustomURLSpan(span.getURL().replace("http://", "scheme://"));
    s.setSpan(span, start, end, 0);
}
textView.setText(builder);
public class CustomURLSpan extends URLSpan {

    public CustomURLSpan(String url) {
        super(url);
    }

    @Override public void onClick(View widget) {
        // custom on click behaviour here
    }
}
how can I call Html.FromHtml inside Value Converter in PCL?

how can I call Html.FromHtml inside Value Converter in PCL?


By : shamshad
Date : March 29 2020, 07:55 AM
To fix the issue you can do The Html.FromHtml refers to Html class from Android, see here
So the converter should be in the Android app, not in PCL.
Android Html.fromHtml(String) doesnt work

Android Html.fromHtml(String) doesnt work


By : Tech Selva
Date : March 29 2020, 07:55 AM
Hope this helps Android support some Html tags. you can see supported tags by android.
Supproted Html Tag by Android
code :
public class HtmlTagHandler implements Html.TagHandler {
boolean first = true;
String parent = null;
int index = 1;
private int mListItemCount = 0;
private Vector<String> mListParents = new Vector<String>();

@Override
public void handleTag(final boolean opening, final String tag, Editable output, final XMLReader xmlReader) {

    if (tag.equals("ul") || tag.equals("ol") || tag.equals("dd")) {
        if (opening) {
            mListParents.add(tag);
        } else mListParents.remove(tag);

        mListItemCount = 0;
    } else if (tag.equals("li") && !opening) {
        handleListTag(output);
    } else if (tag.equalsIgnoreCase("code")) {
        if (opening) {
            output.setSpan(new TypefaceSpan("monospace"), output.length(), output.length(), Spannable.SPAN_MARK_MARK);
        } else {
            Log.d("COde Tag", "Code tag encountered");
            Object obj = getLast(output, TypefaceSpan.class);
            int where = output.getSpanStart(obj);

            output.setSpan(new TypefaceSpan("monospace"), where, output.length(), 0);
        }
    }

}

private Object getLast(Editable text, Class kind) {
    Object[] objs = text.getSpans(0, text.length(), kind);
    if (objs.length == 0) {
        return null;
    } else {
        for (int i = objs.length; i > 0; i--) {
            if (text.getSpanFlags(objs[i - 1]) == Spannable.SPAN_MARK_MARK) {
                return objs[i - 1];
            }
        }
        return null;
    }
}

private void handleListTag(Editable output) {
    if (mListParents.lastElement().equals("ul")) {
        output.append("\n");
        String[] split = output.toString().split("\n");

        int lastIndex = split.length - 1;
        int start = output.length() - split[lastIndex].length() - 1;
        output.setSpan(new BulletSpan(15 * mListParents.size()), start, output.length(), 0);
    } else if (mListParents.lastElement().equals("ol")) {
        mListItemCount++;

        output.append("\n");
        String[] split = output.toString().split("\n");

        int lastIndex = split.length - 1;
        int start = output.length() - split[lastIndex].length() - 1;
        output.insert(start, mListItemCount + ". ");
        output.setSpan(new LeadingMarginSpan.Standard(15 * mListParents.size()), start, output.length(), 0);
    }
}

}
 public static String getHtmlText(String[] s) {
    String ulStart = "<ul>";

    for (int i = 0; i < s.length; i++) {
        ulStart += "<li>" + s[i] + "</li>";
    }

    ulStart += "</ul>";
    return ulStart;
}
textview.setText(Html.fromHtml(htmlString, null, new HtmlTagHandler()));
Android - Html.fromHtml() with custom fonts

Android - Html.fromHtml() with custom fonts


By : Mario Ferrante
Date : March 29 2020, 07:55 AM
this one helps. I'm trying to assign HTML text into a TextView. Here's a sample of the HTML: ,
Is there a way to make fromHtml recognise custom fonts?
Related Posts Related Posts :
  • MPAndroidChart: unwanted spacing between XAxis and data line
  • How to parse JsonArray values in Android
  • Lifecycle of tabs in Android
  • What are the problems in using Intent to pass objects from one activity to another
  • Android : Multi line text EditText inside BottomSheetDialog
  • set savedInstanceState Bundle in Activity
  • Change progressDialog font to custom on Android
  • Why POT textures work slower than non-pot?
  • PersonAPI Google+ "PERMISSION_DENIED" Error
  • Using UserDialogs in Android
  • Get lightness of ambiance with react-native?
  • Lines between code in android
  • Sort list in two differents ways
  • Android Studio Change Array Value
  • Disable webview browser tester ( android )
  • Are there any cons of creating Singleton class with static field to communicate between activities in Android?
  • Change fragment background on create view dynamically
  • Android Getting coordinates of an image
  • unfortunately project has stopped after adding admob ads
  • Error inflating Class ImageView on RecyclerView
  • Android percent layouts
  • App Inventor - Input an item to a list and then properly display the list
  • Android, CountDownTimer latency
  • How to detect MotionEvent.ACTION_DOWN in service Android
  • code in HTML for sharing content over Phone gap interacting with other app as like ACTION_SEND indent on the native andr
  • Android - Displaying decimal as formatted fraction (and vice versa)
  • Android -FAB Behaviour with half list
  • Enabling externalNativeBuild with ABI split
  • Issue with multiscreen design
  • Upload binary file with retrofit 2 in Android
  • R.layout is'nt recogized by the studio
  • android - RecyclerView updating every second and have a longPressListener
  • What's the best way (in Android dev) to consume REST API (in addition to Retrofit)?
  • Which Android SDK Packages do I need for Cordova and Android 4+
  • Android & Retrofit2 - posting image file in multipart request
  • Calabash directory structure for testing both Android and iOS
  • javafxports 8.60.7 - using Back button on Android - none exit application
  • Create file from drawable to send with sendbird
  • Firebase app integration error
  • Xamarin No resource found that matches the given name (at 'colorAccent' with value '@color/accent ')
  • Will Firebase provide tests for other OS and does it support manual testing?
  • Android - Obtain self-signed server certificate and add to trusted keystore
  • Error:(25, 46) error: @InjectViews must be a List or array
  • What is the difference between 'Make' and 'Gradle-aware Make'?
  • How to know if user has verified his/her email address
  • Importing Android-Download-Manager library results "failed to resolve"?
  • Showing particular area in google PlacePicker
  • Sharing pdf to Evernote not working in Android
  • Android : Google signin is not working in release mode
  • How to save an intent object and later retrieve it
  • Convert YUV Image into greyscale Image - Same Result as RGB to Grayscale?
  • bulkTransfer makes the application crash
  • How to aspect fill programmatically? [Android]
  • I lost my key store password, I want to update my app on plays store with same keystore
  • How to find the minimum and maximum dates from three tables even if there is no date in one table in android sqlite
  • Unparseable date: "10:40:54" (at offset 0)
  • Keep count of consumable in-app purchases using Firebase Realtime Database
  • Proguard with Parceler and Realm
  • Check whether the file is already exists Android not working
  • Update value to mutiply objects by Transaction in Firebase
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com