Android resources html files

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

TextView to display simple HTML

License

SufficientlySecure/html-textview

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Читайте также:  Python syntax for arrays

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

This project has been stopped. 4.0 is the last release.

Feel free to fork this project and take over maintaining.

HtmlTextView is an extended TextView component for Android, which can load very simple HTML by converting it into Android Spannables for viewing.

In addition to a small set of HTML tags, the library allows to load images from the local drawables folder or from the Internet.

This library is kept tiny without external dependencies.

Add this to your build.gradle:

repositories < jcenter() >dependencies
org.sufficientlysecure.htmltextview.HtmlTextView android:id="@+id/html_text" android:layout_width="match_parent" android:layout_height="match_parent" android:textAppearance="@android:style/TextAppearance.Small" />
HtmlTextViewhtmlTextView = (HtmlTextView) view.findViewById(R.id.html_text); // loads html from string and displays cat_pic.png from the app's drawable folderhtmlTextView.setHtml("

Hello wold

  • cats
  • dogs
\"
cat_pic\"/>", newHtmlResImageGetter(htmlTextView));
HtmlTextViewhtmlTextView = (HtmlTextView) view.findViewById(R.id.html_text); // loads html from string and displays cat_pic.png from the app's assets folderhtmlTextView.setHtml("

Hello wold

  • cats
  • dogs
\"
cat_pic\"/>", newHtmlAssetsImageGetter(htmlTextView));
HtmlTextView htmlTextView = (HtmlTextView) view.findViewById(R.id.html_text); // loads html from string and displays http://www.example.com/cat_pic.png from the Internet htmlTextView.setHtml("

Hello wold

\"
http://www.example.com/cat_pic.png\"/>", new HtmlHttpImageGetter(htmlTextView));
HtmlTextView htmlTextView = (HtmlTextView) view.findViewById(R.id.html_text); // loads html from raw resource, i.e., a html file in res/raw/, // this allows translatable resource (e.g., res/raw-de/ for german) htmlTextView.setHtml(R.raw.help, new HtmlHttpImageGetter(htmlTextView));
TextView android:id="@+id/html_text" android:layout_width="match_parent" android:layout_height="match_parent" android:textAppearance="@android:style/TextAppearance.Small" />
TextViewhtmlTextView = (TextView) view.findViewById(R.id.html_text); // loads html from string and displays cat_pic.png from the app's drawable folderSpannedformattedHtml = HtmlFormatter.formatHtml(newHtmlFormatterBuilder().setHtml("

Hello wold

  • cats
  • dogs
\"
cat_pic\"/>").setImageGetter(newHtmlResImageGetter(htmlTextView.getContext()))); htmlTextView.setText(formattedHtml);

Extended support by HtmlTextView

HtmlTextView now supports HTML tables (to a limited extent) by condensing the text into a link which developers are able to render in a native WebView. To take advantage of the feature you’ll need to:

  1. implement a ClickableTableSpan which provides access to the table HTML (which can be forwarded to a WebView)
  2. provide a DrawTableLinkSpan which defines what the table link should look like (i.e. text, text color, text size)

Take a look at the project’s sample app for an example.

Support for A tag click listener

textView.setOnClickATagListener(new OnClickATagListener() < @Override public void onClick(View widget, @Nullable String href) < Toast.makeText(MainActivity.this, href, Toast.LENGTH_SHORT).show(); >>); 

We recognize the standard table tags:

as well as the tags extended by HtmlTextView. However, support doesn’t currently extend to tags natively supported by Android (e.g. , , ) which means tables will not include the extra styling.

Источник

Where and how to put HTML files in Android app resource files?

I have a bunch of those methods for my unit tests, this one extracts the data to a file: Solution 2: Put in the file and then getting back the using Solution 3: This worked form me: Put all your html code in value resource file and then retrieve it using @Html.Raw(. ) Please see the images below: Question: I’m using Android Studio/Gradle. app\src\main\android_asset folder has the file called chart.html.. I’m trying to load this file to my webview like this:

Where and how to put HTML files in Android app resource files?

I am creating a simple Android Bible app. Bible text is structured in the bible folder as:

. ├── bible │ ├── book_one │ │ ├── chapter_one.html │ │ ├── chapter_two.html │ │ └── [. ] │ ├── book_two │ │ ├── chapter_one.html │ │ ├── chapter_two.html │ │ └── [. ] │ ├── [. ] | [. ] [. ] 
  • where is the appropriate place to put the bible folder in Android app project and,
  • how do I import it with the Android Studio (version Artic Fox) and,
  • how do I load those files to use it within my code?

P.S. I’m new in the Android app dev world.

In order to put HTML files in your existing android studio project please follow steps below:

1: To add a local HTML file into your Android project there must be an asset folder in it. To create an asset folder in Android studio open your project in Android mode first as shown in the below image.

Step 1

2: Go to the app > right-click > New > Folder > Asset Folder and create the asset folder.

Step 2

3: Android Studio will open a dialog box . Keep all the settings default. Under the target source set, option main should be selected. and click on the finish button.

Step 3

4: The asset folder has been created as shown in the below image. Go to assets > right-click > New > File and a dialog box will pop up.

Step 4

5: Provide a name to your file as shown below. For example demo.html

Step 5

6: Or you can simply paste your html files into assets folder created in step 4.

7: You are done with it! Happy Coding

8: This way you can use your files from Assets folder :

webView.loadUrl("file:///android_asset/filename.html"); 

It is very easy to implement. You have to just follow two simple steps as follows:

Step 1: Create an HTML page anywhere on your PC and then copy the required HTML files.

Step 2: Paste it inside the assets folder by right-clicking on the assets folder as shown in the below image.

Android HTML resource with references to other, I would like to avoid duplicating the files (one copy in res/drawables, the other in assets) to keep the file size of the app down. – …

How to load html file to android app?

I’m new to android development and I’m trying to figure out how to load an HTML file that I have which contains a video. Everytime I run my app on my mobile it crashes.

This is my code which is found in the onCreate main class.

WebView wv = (WebView)this.findViewById(R.id.video); WebSettings wbset=wv.getSettings(); wbset.setJavaScriptEnabled(true); wv.setWebViewClient(new WebClientClass()); wv.loadUrl("file:///assets/video.html"); 

I have the video in the assets folder. This is my manifest xml class.

And the activity is right here.

For further detail refer Printing HTML Documents.

Use this instead of you use :-

You need to get the path of the asset folder. You can get the path of Asset folder using this : wv.loadUrl(context.getAssets().open(«video.html»)).

Using JSON File in Android App Resources, I used @kabuko’s answer to create an object that loads from a JSON file, using Gson, from the Resources:. package com.jingit.mobile.testsupport; import java.io.*; import android.content.res.Resources; import android.util.Log; import com.google.gson.Gson; import com.google.gson.GsonBuilder; /** * An …

How to put HTML code into a .resx resource file?

Strange, that no one asked this before.

I am creating templated HTML emails for 4 languages. I want to put the HTML templates into my . resx files to have easy, internationalized access to them from code. Like so:

But, obviously, the compiler complains about the HTML inside the .resx file. Is there a way to use HTML (or XML at all) in .resx files. How?

I am using .NET version 4 and dotliquid as templating Engine, if that matters.

Suggestion: Create the file you want, name it the way you want, e.g «my_template.html» then add this file to your project.

Click on it, then select in the properties window «Build Action» and set it to «Embedded Resource».

Whenever you want to access this file, you can use something like this ( no with proper using block :

 public static string ReadTextResourceFromAssembly(string name) < using ( var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream( name ) ) < return new StreamReader( stream ).ReadToEnd(); >> 

Tailor it to your needs. The method above obtains the resource, say you have put your resource in your project MyProject in a subdirectory «HtmlTemplates and called it «my_template.html», then you can access it by the name MyProject.HtmlTemplates.my_template.html

You can then write it out to file or use it directly, etc.

This has some major benefits: You see your html file in your project, it has the html extension, so editing it in Visual Studio has syntax highlighting and all tools applied to .html files.

I have a bunch of those methods for my unit tests, this one extracts the data to a file:

 public static void WriteResourceToFile(string name, string destination) < using ( var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream( name ) ) < if ( stream == null ) < throw new ArgumentException( string.Format( "Resource '' not found", name), "name" ); > using ( var fs = new FileStream( destination, FileMode.Create ) ) < stream.CopyTo( fs ); >> > 

Put encoded html in the .resx file and then getting back the html using

@Html.Raw(Server.HtmlDecode(. resource. )); 

This worked form me: Put all your html code in value resource file and then retrieve it using @Html.Raw(. ) like I did it here

   @Html.Raw(Resources.Listino.Cassette   

Resource File

in the Listino resource File:

Well, I found a way like that:

First I created partial view in multiple languages and put the path of this partial views into .resx files. Next, I called @Html.Partial() method with the Resource string.

Please see the images below:

Views

Resx file

Use HTML and CSS Files in Android Apps, First, create an Android Application Project in Eclipse. Layout XML file. Then open the Layout XML file. Drag the first Linear Layout then WebView Element to the Relative Layout of the Activity. XML File Code. Then make a HTML and CSS file. Copy files into the assets folder as in the following: Now open the …

Loading html file to webview on android from assets folder using Android Studio

I’m using Android Studio/Gradle.

app\src\main\android_asset folder has the file called chart.html..

I’m trying to load this file to my webview like this:

WebView view = new WebView(this); view.getSettings().setJavaScriptEnabled(true); view.loadUrl("file:///android_asset/chart.html"); setContentView(view); 

But I always get the error: could not be loaded because ERR_FILE_NOT_FOUND .

The directory name should be assets not android_assets

Do like this:

As shown in the above pics just right click on your app->New->Folder->Assets Folder

Now put your .html file here in assets folder.

Remaining is same in code what you did.

WebView view = new WebView(this); view.getSettings().setJavaScriptEnabled(true); view.loadUrl("file:///android_asset/hello.html"); setContentView(view); 

I use many productFlavors with different applicationId.

If I attempt to load a html file from res/raw/file.html I get a ClassNotFoundException Didn’t find class «product.flavor.package.R$raw»

The R.java file has a different Package name.

It look’s like you can’t load a URL from file like : webView.loadUrl( «file:///android_res/raw/page.html»); because the WebView try to use the R.class file with has a different package name.

I assume the err_file_not_found from loading a html file from assets has the same problem but you don’t see the exception. ( webView.loadUrl( «file:///android_assets/page.html» ); )

With this small work around I solve my problem :

try < AssetManager assetManager = context.getAssets(); InputStream stream = assetManager.open("page.html"); BufferedReader r = new BufferedReader(new InputStreamReader(stream)); StringBuilder total = new StringBuilder(); String line; while ((line = r.readLine()) != null) < total.append(line).append("\n"); >webView.loadDataWithBaseURL(null, total.toString(), "text/html", "UTF-8", null); > catch (Exception ****) < Log.e(TAG, "Load assets/page.html", ****); >

I hope this helps. Stephan

Answer from Gugelhupf but with raw resource.
Advantage from this solution: you keep translation working!

WebView webView = findViewById(R.id.about_text); try < InputStream inputStream = getResources().openRawResource(R.raw.about); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); StringBuilder stringBuilder = new StringBuilder(); String line; while ((line = bufferedReader.readLine()) != null) < stringBuilder.append(line).append("\n"); >webView.loadDataWithBaseURL(null, stringBuilder.toString(), "text/html", "UTF-8", null); > catch (IOException e)

Where and how to put HTML files in Android app, 1: To add a local HTML file into your Android project there must be an asset folder in it. To create an asset folder in Android studio open your project in Android mode first as shown in the below image. 2: Go to the app > right-click > New > Folder > Asset Folder and create the asset folder. 3: Android Studio will open a dialog box.

Источник

Оцените статью