KodeEditor
v4.0.1
一个简单的代码编辑器,带有语法突出显示和夹紧以缩放

| 掌握 |
|---|
查看完整示例的演示应用程序( app模块)。
要使用此库,只需将其包含在您的依赖项中
repositories {
...
maven { url "https://jitpack.io" }
}
在您的项目build.gradle文件中
dependencies {
...
def codeEditorVersion = "v4.0.1"
implementation("com.github.markusressel:KodeEditor:${codeEditorVersion}")
}
在您所需的模块build.gradle文件中。
要使用此编辑器,只需将与此类似的内容添加到您所需的布局XML文件:
<de.markusressel.kodeeditor.library.view.CodeEditorLayout
android:id="@+id/codeEditorView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:ke_divider_color="?android:attr/textColorPrimary"
app:ke_divider_enabled="true"
app:ke_editor_backgroundColor="?android:attr/windowBackground"
app:ke_editor_maxZoom="10.0"
app:ke_lineNumbers_backgroundColor="#ccc"
app:ke_lineNumbers_textColor="#000"
app:ke_minimap_enabled="true"
app:ke_minimap_maxDimension="200dp"
app:ke_minimap_borderColor="#000"
app:ke_minimap_indicatorColor="#f00"
/>
目前尚无文档中使用的语言的自动检测。您必须自己管理语法荧光笔,并在适当时致电setSyntaxHighlighter方法。
请看一下Kodehighlighter部分。
请看一下Kodehighlighter部分。
Kodeeditor可以通过多种方式进行样式:
| 姓名 | 描述 | 类型 | 默认 |
|---|---|---|---|
| ke_lineNumbers_textColor | 指定行号的文本颜色 | 颜色 | android.R.attr.textColorPrimary |
| ke_lineNumbers_backgroundColor | 指定行号视图的背景颜色 | 颜色 | android.R.attr.windowBackground |
| ke_divider_enabled | 指定是否应在行号和实际代码编辑器内容之间绘制分隔线 | 布尔 | true |
| ke_divider_color | 指定分隔线的颜色(如果ke_divider_enabled设置为false ,则无效) | 颜色 | android.R.attr.textColorPrimary |
| ke_editor_backgroundColor | 指定代码编辑器视图的背景颜色 | 颜色 | android.R.attr.windowBackground |
| ke_editor_maxzoom | 指定编辑器的最大缩放级别 | 漂浮 | 10 |
| ke_minimap_enabled | 启用最小值 | 布尔 | true |
| ke_minimap_maxdimension | 指定两个轴的最小值的最大尺寸 | 方面 | 150dp |
| ke_minimap_bordercolor | 指定最小值的边框颜色 | 颜色 | Color.BLACK |
| ke_minimap_indicatorColor | 指定最小值指示器的颜色 | 颜色 | Color.RED |
您可以直接在布局中的视图上使用这些属性:
<de.markusressel.kodeeditor.library.view.CodeEditorView
android:id="@+id/codeEditorView"
android:layout_width="match_parent"
android:layout_height="match_parent"
[...]
app:ke_divider_color="?android:attr/textColorPrimary"
app:ke_divider_enabled="true"
app:ke_editor_backgroundColor="?android:attr/windowBackground"
app:ke_editor_maxZoom="10.0"
app:ke_lineNumbers_backgroundColor="#ccc"
app:ke_lineNumbers_textColor="#000"
app:ke_minimap_enabled="true"
app:ke_minimap_maxDimension="200dp"
app:ke_divider="true"
[...] />
或在您的应用程序主题(DEM应用中的styles.xml )中指定它们,以在全球应用样式:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Other theme attributes of your application -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<!-- CodeEditorView -->
<item name="ke_lineNumbers_backgroundColor">#ccc</item>
<item name="ke_lineNumbers_textColor">#000</item>
<item name="ke_divider_enabled">false</item>
<item name="ke_divider_color">#000</item>
<item name="ke_editor_backgroundColor">#fff</item>
<item name="ke_editor_maxZoom">10.0</item>
<item name="ke_editor_followCursor">true</item>
<item name="ke_minimap_enabled">true</item>
<item name="ke_minimap_maxDimension">200dp</item>
[...]
</style>
</resources>
也可以使用代码指定所有样式属性。由于KodeEditorLayout只是一个包装器,可以扩展使用行号的CodeEditorView和最小值来使用其中一些方法,因此首先访问KodeEditorLayout的匹配属性。
| 姓名 | 描述 | 类型 |
|---|---|---|
| 文本 | 在编辑器中设置给定文本。 | 细绳 |
| setText(@StringRes) | 将给定的字符串资源设置为编辑器中的文本。 | int |
| 语言书 | 获取/设置用于突出显示的活动语言规则簿。使用null完全禁用突出显示。 | 语言书? |
| 可编辑 | 如果编辑器内容是可编辑的,则获取/设置。 | 布尔 |
| 姓名 | 描述 | 类型 |
|---|---|---|
| Showdivider | 如果显示行号和代码编辑器之间的分隔线,则获取/设置。 | 布尔 |
| 亚麻生生物 | 设置基于行总数显示的文本以显示行号 | (长) - >列表 |
| 姓名 | 描述 | 类型 |
|---|---|---|
| Showminimap | 如果显示了最小值,请获取/设置。 | 布尔 |
| 最小值 | 获取/设置像素中最小化的最大尺寸。 | 漂浮 |
| minimapborderWidth | 获取/设置MiniMap边框大小以像素为单位。 | 数字 |
| 最小值 | 获取/设置Minimap边框颜色。 | @ColorInt |
| MinimapIndicatorColor | 获取/设置MiniMAP指示器颜色。 | @ColorInt |
| 最小值 | 获取/设置MiniMAP定位重力。 | int |
要使用这些API方法,请使用codeEditorLayout.codeEditorView属性。
| 姓名 | 描述 | 类型 |
|---|---|---|
| 文本 | 在编辑器中设置给定文本。 | 细绳 |
| setText(@StringRes) | 将给定的字符串资源设置为编辑器中的文本。 | int |
| getlinecount() | 返回当前的线计数。 | 长的 |
| 语言书 | 获取/设置用于突出显示的活动语言规则簿。使用null完全禁用突出显示。 | 语言书? |
| 可编辑 | 如果编辑器内容是可编辑的,则获取/设置。 | 布尔 |
| 哈塞尔 | 当选择范围时,是真的。 | 布尔 |
| SELECTIONSTART | 当前选择的开始索引。 | int |
| SelectionEnd | 当前选择的最终索引。 | int |
| SelectionChangedListener | 获取/设置侦听器以进行选择更改。 | SelectionChangedListener? |
GitHub用于社交编码:如果您想编写代码,我会通过此存储库的分叉请求来鼓励贡献。为错误和新功能创建GitHub门票,并评论您感兴趣的票。
MIT License
Copyright (c) 2018 Markus Ressel
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.