Skip to content

sunfusheng/CodeViewer

Repository files navigation

CodeViewer

Android 端代码查看器,支持的功能:

1、几乎加载所有格式代码,具体查看Google开源的code-prettify
2、支持白天夜晚模式,可以设置自定义颜色
3、支持是否显示代码行号

效果图


Gradle:

api 'com.sunfusheng:code-viewer:1.0.0'

使用

<com.sunfusheng.codeviewer.CodeView
    android:id="@+id/vCodeView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

// 1、从assets文件夹下加载文件的内容
val sourceCode = CodeViewUtil.getStringFromAssetsFile(context, filePath)
// 2、生成html字符串
val sourceCodeHtml = CodeHtmlGenerator.generate(filePath,sourceCode,isNightMode,showLineNums)
// 3、在UI线程中加载源码的Html字符串,步骤1和2应该放到子线程中
vCodeView.loadCodeHtml(sourceCodeHtml)

感谢

1、google/code-prettify

2、ThirtyDegreesRay/OpenHub


关于我

GitHub: sunfusheng

个人邮箱: sfsheng0322@126.com

个人博客: sunfusheng.com

简书主页

新浪微博

About

Android 端代码查看器

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published