Nasa Editor Library is a powerful library for running or previewing HTML, CSS, and JavaScript code on Android devices.
In your settings.gradle file, ensure JitPack is included:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
// other repositories
maven { url 'https://jitpack.io' }
}
}dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
// other repositories
maven { url = uri("https://jitpack.io") }
}
}Add Nasa Editor Library Dependency
In your app-level build.gradle file, add the dependency:
dependencies {
// Nasa Editor Library
implementation 'com.github.CodeWithTamim:Nasa-Editor-Library:1.0.4'
}dependencies {
// Nasa Editor Library
implementation("com.github.CodeWithTamim:Nasa-Editor-Library:1.0.4")
}Make sure to add the following permission to your AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />Add the NasaEditorView to your XML layout:
<com.nasahacker.editorlibrary.widget.NasaEditorView
android:id="@+id/editor_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>import com.nasahacker.editorlibrary.widget.NasaEditorView;
public class MainActivity extends AppCompatActivity {
private NasaEditorView editorView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editorView = findViewById(R.id.editor_view);
editorView.setHtmlCode("<h1>Hello World</h1>");
editorView.setCssCode("h1 { color: red; }");
editorView.setJsCode("console.log('Hello World');");
editorView.runCode();
}
}import com.nasahacker.editorlibrary.widget.NasaEditorView
class MainActivity : AppCompatActivity() {
private lateinit var editorView: NasaEditorView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
editorView = findViewById(R.id.editor_view)
editorView.setHtmlCode("<h1>Hello World</h1>")
editorView.setCssCode("h1 { color: red; }")
editorView.setJsCode("console.log('Hello World');")
editorView.runCode()
}
}getDefaultHtml(): Provides the default HTML template.getDefaultCss(): Provides the default CSS template.getDefaultJs(): Provides the default JavaScript template.getCssCode(): Retrieves the current CSS code.getJsCode(): Retrieves the current JavaScript code.getHtmlCode(): Retrieves the current HTML code.runCode(): Combines the HTML, CSS, and JavaScript code and previews it in the WebView.setHtmlCode(html: String): Updates the current HTML code.setCssCode(css: String): Updates the current CSS code.setJsCode(js: String): Updates the current JavaScript code.getInstance(): Provides an instance of NasaEditorView.
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
Made with ❤️ by Tamim Hossain