Androidda TextViewni ichida htmlni chiqarish

+7 ovoz
96 marta ko‘rilgan
so‘radi 26 fevral, 17 vejon (2,960 bal)
Assalom alaykum.

Androidda TextViewni ichida htmlni chiqarish qanday mumkin?

Deylik bizda html kod bor. Shu kodni TextView ichida chiqarish kerak(ko'rinishini o'zgartirmagan holda).

3 Javoblar

+4 ovoz
javob berdi 26 fevral, 17 Kenjebaev (1,013 bal)
tanlangan 26 fevral, 17 vejon
 
Eng yaxshi javob

Savolni tushingan bo'lsam sizda html teglar ko'rinib qolmoqda.

Nougat`gacha

textView.setText(Html.fromHtml("<html>Hello, World!</html>"));

Nougat`dan boshlab va undan kattalari uchun:

textView.setText(Html.fromHtml("<html>Hello, World!</html>", Html.FROM_HTML_MODE_COMPACT));

Qo'shimcha ma'lumotlar uchun:

https://developer.android.com/reference/android/text/Html.html#fromHtml

+3 ovoz
javob berdi 26 fevral, 17 Axrorxo'ja (733 bal)

Assalom alaykum

Xpath yoki regex yozib htmldan chiqarib oling,chrome da xpathhelper dgan extensioni bor mishka bilan belgilasa o'zi eng optimal xpathni chiqarib beradi,yoki textview o'rniga webview ishlating

webView.loadData(yourData, "text/html; charset=utf-8", "UTF-8");
xpathda bunday qilgandim 
                        String pageSource = gSource(startPage);
                        HtmlCleaner htmlCleaner = new HtmlCleaner();
                        CleanerProperties props = htmlCleaner.getProperties();
                        TagNode node = htmlCleaner.clean(pageSource);
                        props.setTransSpecialEntitiesToNCR(true);
                        Document hhcDocument;
                        NodeList nodeListTitle = null;
                        NodeList nodeListImages = null;
                        NodeList nodeListTime = null;
                        try
                            {
                                hhcDocument = new DomSerializer(props).createDOM(node);
                                nodeListTitle = (NodeList) xPath.compile("//h3[@class='panel-title']/a").evaluate(hhcDocument.getDocumentElement(), XPathConstants.NODESET);
                                nodeListImages = (NodeList) xPath.compile("//div[@class='col-md-5']/img[@class='img-responsive']/@src").evaluate(hhcDocument.getDocumentElement(), XPathConstants.NODESET);
                                nodeListTime = (NodeList) xPath.compile("//div[@class='panel panel-primary']/div[@class='panel-footer']/text()[2]").evaluate(hhcDocument.getDocumentElement(), XPathConstants.NODESET);
                            } catch (ParserConfigurationException | XPathExpressionException e)
                            {
                                e.printStackTrace();
                            }
                        PostObject postObject;
                        for (int i = 0; i < nodeListTitle.getLength(); i++)
                            {
                                postObject = new PostObject();
                                postObject.setTitle(Util.cleanerUnicode(nodeListTitle.item(i).getTextContent()));
                                postObject.setPostUrl(nodeListTitle.item(i).getAttributes().getNamedItem("href").getNodeValue());
                                postObject.setImageUrl(Util.cleanerUnicode(nodeListImages.item(i).getTextContent()));
                                postObject.setDate(nodeListTime.item(i).getTextContent().trim());
                            }

0 ovoz
javob berdi 27 fevral, 17 Faxriddin (823 bal)

String o'zgaruvchiga HTML kodlar yozamiz Quyidagi shalikda misol uchun

String formattedText = "Bu <i>TextViewga </i> <font color='#00ccff'>HTML kodda rang</font> berilgan";
keyin TexdtViewga shu stringni o'rnatamiz
tv.setText(Html.fromHtml(formattedText));

Assalomu alaykum, yordam.uz saytimizga xush kelibsiz.

Bu saytda o`zingizni qiziqtirgan savollarga javob olishingiz va o`z sohangiz bo`yicha savollarga javob berishingiz mumkin.

Bizning Oilamizga a'zo bo`lganingiz uchun chuqur Minnatdorchilik bildiramiz !!!

Telegram kanal YordamUzRss

...