Displaying MD or Markdown files and text in Android

Mukesh Solanki
2 min readFeb 11, 2019

--

MarkdownView is a simple library that helps you display Markdown text or files on Android as an HTML page just like Github.

Getting started

It’s really simple to integrate MarkdownView in android. All you need to do make the following change to you build gradle under the app module.

Step 1. Add the JitPack repository to your build file. Add it in your root build.gradle at the end of repositories:

allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}

Step 2. Add the dependency

dependencies {
implementation 'com.github.mukeshsolanki:MarkdownView-Android:<latest-version>'
}

How to use MarkdownView

It’s fairly simple and straight forward to use MarkdownView in your application. Just add the following in your layout where you want to display the markdown file/text.

<com.mukesh.MarkdownView
android:id="@+id/markdown_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

and reference it in your activity/fragment and assign the markdown text/file likewise.

MarkdownView markdownView = (MarkdownView) findViewById(R.id.markdown_view);
markdownView.setMarkDownText("# Hello World\nThis is a simple markdown"); //Displays markdown text
...
markdownView.loadMarkdownFromAssets("README.md"); //Loads the markdown file from the assets folder
...
File markdownFile=new File("filePath");
markdownView.loadMarkdownFromFile(markdownFile); //Loads the markdown file.
Sample

--

--

Mukesh Solanki

Converts coffee to code! Writes about software development, automation, android. Connect with me on https://www.mukeshsolanki.com