Table of Contents
CodeViewCodeView ,按照字面意思,就是用来显示代码,并有能够进行代码高亮的一个View类型。这里是通过hightlight.js 渲染代码,可以自动识别主流的各种语言比如java,c++,c#,python,bash,ruby。。。。等等等语言并且有很多种主题风格,可以自由选择一种主题,然后将其显示比如:
This is a code
This is another code
Home Web Front-end HTML Tutorial [开源] Android 代码高亮控件_html/css_WEB-ITnose

[开源] Android 代码高亮控件_html/css_WEB-ITnose

Jun 24, 2016 am 11:14 AM

CodeViewCodeView ,按照字面意思,就是用来显示代码,并有能够进行代码高亮的一个View类型。这里是通过hightlight.js 渲染代码,可以自动识别主流的各种语言比如java,c++,c#,python,bash,ruby。。。。等等等语言并且有很多种主题风格,可以自由选择一种主题,然后将其显示比如:

既可以显示单个代码片段,也可以把html文件中所有指定的代码替换为高亮显示出来。比如对于下面的原本的html文件。

<!DOCTYPE html><html><head>    <title></title></head><body><h1 id="This-is-a-code">This is a code</h1><pre class="code">#include<stdio.h>int main(){    printf("hello world");}
Copy after login

This is another code

class Main{    private String name;    Main(String name){        this.name=name;    }    public static void main(String []args){        Main main=new Main("hello");        System.out.println("init");    }}
Copy after login

如果要把其中的代码替换为高亮显示的话呢,可以这样,通过原来放代码的标签的类,来将代码高亮显示。可以用 css 的选择器,来选中需要高亮的代码区域.就像这样

  java codeView.showCodeHtmlByCssSelect(Constant.HTML,".code");
Copy after login

是不是很强大,如果感兴趣的话呢,可以到这里获取,这里有获取方法和详细的使用说明github地址: https://github.com/Thereisnospon/CodeView如果觉得不错的话,可以点击这里点个赞什么的的

这里写图片描述

当然,这是第一次尝试写开源库,如果有哪些不好的地方,或者有什么bug,可以给我一点建议,每个批评都是一次学习的机会可以在项目的issue部分提出建议,也可以发邮件给我

5

邮箱:thereisnospon@qq.com

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update? Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update? Mar 04, 2025 pm 12:32 PM

Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?

How do I use HTML5 form validation attributes to validate user input? How do I use HTML5 form validation attributes to validate user input? Mar 17, 2025 pm 12:27 PM

How do I use HTML5 form validation attributes to validate user input?

What is the purpose of the <iframe> tag? What are the security considerations when using it? What is the purpose of the <iframe> tag? What are the security considerations when using it? Mar 20, 2025 pm 06:05 PM

What is the purpose of the <iframe> tag? What are the security considerations when using it?

How to efficiently add stroke effects to PNG images on web pages? How to efficiently add stroke effects to PNG images on web pages? Mar 04, 2025 pm 02:39 PM

How to efficiently add stroke effects to PNG images on web pages?

What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

What is the purpose of the <meter> element?

What are the best practices for cross-browser compatibility in HTML5? What are the best practices for cross-browser compatibility in HTML5? Mar 17, 2025 pm 12:20 PM

What are the best practices for cross-browser compatibility in HTML5?

What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

What is the purpose of the <datalist> element?

What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

What is the purpose of the <progress> element?

See all articles