android项目实战之编辑器集成

引言

项目需要用到编辑器,采用RichEditor,如下效果

实现

1. 引入库2

implementation 'jp.wasabeef:richeditor-android:2.0.0'

2.  XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_marginBottom="@dimen/dp_60"
    android:theme="@style/customTheme"
    >
    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/app_color_9b">

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <ImageButton
                android:id="@+id/action_undo"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="@null"
                android:contentDescription="@null"
                android:src="@mipmap/undo" />

            <ImageButton
                android:id="@+id/action_redo"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="@null"
                android:contentDescription="@null"
                android:src="@mipmap/redo" />

            <ImageButton
                android:id="@+id/action_bold"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="@null"
                android:contentDescription="@null"
                android:src="@mipmap/bold" />

            <ImageButton
                android:id="@+id/action_heading1"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="@null"
                android:contentDescription="@null"
                android:src="@mipmap/h1" />

            <ImageButton
                android:id="@+id/action_heading2"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="@null"
                android:contentDescription="@null"
                android:src="@mipmap/h2" />

            <ImageButton
                android:id="@+id/action_heading3"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="@null"
                android:contentDescription="@null"
                android:src="@mipmap/h3" />

            <ImageButton
                android:id="@+id/action_heading4"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="@null"
                android:contentDescription="@null"
                android:src="@mipmap/h4" />

            <ImageButton
                android:id="@+id/action_heading5"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="@null"
                android:contentDescription="@null"
                android:src="@mipmap/h5" />

            <ImageButton
                android:id="@+id/action_heading6"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="@null"
                android:contentDescription="@null"
                android:src="@mipmap/h6" />

            <ImageButton
                android:id="@+id/action_insert_image"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="@null"
                android:contentDescription="@null"
                android:src="@mipmap/insert_image" />


        </LinearLayout>

    </HorizontalScrollView>
    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <jp.wasabeef.richeditor.RichEditor
            android:id="@+id/editor"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </androidx.core.widget.NestedScrollView>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="详情预览"
        android:visibility="gone"
        android:textSize="12sp" />

    <TextView
        android:id="@+id/preview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:visibility="gone"/>


</LinearLayout>

3. fragement片段初始化

 private void initEditor(){
        mPreview = (TextView) mActivity.findViewById(R.id.preview);
        mEditor = (RichEditor) mActivity.findViewById(R.id.editor);
        //初始化编辑高度
        mEditor.setEditorHeight(200);
        //初始化字体大小
        mEditor.setEditorFontSize(16);
        //初始化字体颜色
        mEditor.setEditorFontColor(Color.BLACK);
        //初始化内边距
        mEditor.setPadding(10, 10, 10, 10);
        //设置默认显示语句
        mEditor.setPlaceholder("请输入...");
        //设置编辑器是否可用
        mEditor.setInputEnabled(true);

        //mPreview = (TextView) mActivity.findViewById(R.id.preview);

        mEditor.setOnTextChangeListener(new RichEditor.OnTextChangeListener() {
            @Override
            public void onTextChange(String text) {
                mPreview.setText(text);
            }
        });

        mActivity.findViewById(R.id.action_undo).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mEditor.undo();
            }
        });

        mActivity.findViewById(R.id.action_redo).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mEditor.redo();
            }
        });

        mActivity.findViewById(R.id.action_heading1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mEditor.setHeading(1);
            }
        });

        mActivity.findViewById(R.id.action_heading2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mEditor.setHeading(2);
            }
        });

        mActivity.findViewById(R.id.action_heading3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mEditor.setHeading(3);
            }
        });

        mActivity.findViewById(R.id.action_heading4).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mEditor.setHeading(4);
            }
        });

        mActivity.findViewById(R.id.action_heading5).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mEditor.setHeading(5);
            }
        });

        mActivity.findViewById(R.id.action_heading6).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mEditor.setHeading(6);
            }
        });

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/230145.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

cache 2.单机并发缓存

0.对原教程的一些见解 个人认为原教程中两点知识的引入不够友好。 首先是只读数据结构 ByteView 的引入使用是有点迷茫的&#xff0c;可能不能很好理解为什么需要ByteView。 第二是主体结构 Group的引入也疑惑。其实要是熟悉groupcache&#xff0c;那对结构Group的使用是清晰…

springboot3远程调用

RPC 两个服务器之间的调用 远程请求 内部服务之间的调用 可以通过 cloud 注册中心 openfeign等 外部服务的调用 http请求 外部协议 api:远程接口 sdk&#xff1a;本地调用 调用阿里云的天气请求

hbuilder + uniapp +vue3 开发微信云小程序

1、创建项目&#xff1a; 2、创建项目完成的默认目录结构&#xff1a; 3、在根目录新建一个文件夹cloudFns&#xff08;文件名字随便&#xff09;&#xff0c;存放云函数源码&#xff1a; 4、修改manifest.json文件&#xff1a;添加 小程序 appid和cloudfunctionRoot&#xff0…

【EI会议征稿中】2024年第四届人工智能、自动化与高性能计算国际会议(AIAHPC 2024)

2024年第四届人工智能、自动化与高性能计算国际会议&#xff08;AIAHPC 2024&#xff09; 2024 4th International Conference on Artificial Intelligence, Automation and High Performance Computing 2024第四届人工智能、自动化与高性能计算国际会议(AIAHPC 2024)将于20…

docker学习(七、搭建mysql8.2主从)

一、主库搭建 1.构建主库镜像 # 运行mysql镜像&#xff0c;配置端口3307为主库 docker run -p 3307:3306 --name mysql-master --privilegedtrue -v /mydata/mysql-master/log:/var/log/mysql -v /mydata/mysql-master/data:/var/lib/mysql -v /mydata/mysql-master/conf:/etc…

决策树 算法原理

决策树 算法原理 决策树的原理 决策树: 从训练数据中学习得出一个树状结构的模型 决策树属于判别模型 决策树是一种树状结构&#xff0c;通过做出一系列决策 (选择) 来对数据进行划分&#xff0c;这类似于针对一系列问题进行选择。 决策树的决策过程就是从根节点开始&#…

浅谈linux缓冲区的认识!

今天来为大家分享一波关于缓冲区的知识&#xff01;那么既然我们要谈缓冲区&#xff0c;那么就得从是什么&#xff1f;为什么&#xff1f;有什么作用这几个方面来谈论一下缓冲区&#xff01;然后再通过一些代码来更加深刻的理解缓冲区的知识&#xff01; 引言&#xff1a; 是…

Tabbar切换效果(vant)

route 是否开启路由模式 <template><div class"layout-page"><!-- 二级路由出口 --><router-view></router-view><van-tabbar route><van-tabbar-item to"/home">首页<!-- 图标切换为active是高亮 -->&…

“探究HarmonyOS:深入解析鸿蒙操作系统架构”

前言 一、鸿蒙操作系统是什么&#xff1f; 二、为什么要学习鸿蒙操作系统 1.从开发者角度看&#xff1a; 2.从使用者角度看&#xff1a; 总结 前言 随着智能化时代的到来&#xff0c;操作系统的发展也越来越快&#xff0c;人们对于智能化生活的需求也越来越强烈。鸿蒙操作系统作…

LangChain+通义千问+AnalyticDB向量引擎保姆级教程

本文以构建AIGC落地应用ChatBot和构建AI Agent为例&#xff0c;从代码级别详细分享AI框架LangChain、阿里云通义大模型和AnalyticDB向量引擎的开发经验和最佳实践&#xff0c;给大家快速落地AIGC应用提供参考。 前言 通义模型具备的能力包括&#xff1a; 1.创作文字&#xf…

快速学会绘制Pyqt5中的所有图(上)

Pyqt5相关文章: 快速掌握Pyqt5的三种主窗口 快速掌握Pyqt5的2种弹簧 快速掌握Pyqt5的5种布局 快速弄懂Pyqt5的5种项目视图&#xff08;Item View&#xff09; 快速弄懂Pyqt5的4种项目部件&#xff08;Item Widget&#xff09; 快速掌握Pyqt5的6种按钮 快速掌握Pyqt5的10种容器&…

JavaScript常用技巧专题一

文章目录 一、前言二、生成随机颜色的两种方式2.1、生成RandomHexColor2.2、生成随机RGBA 三、复制内容到剪贴板的两种方式3.1、方式13.2、方式2 四、获取URL中的查询参数五、打乱数组六、深拷贝一个对象七、确保元素在可见区域内八、获取当前选中的文本九、浏览器cookie9.1、获…

探索HarmonyOS开发—Slider滑动条组件

Slider Slider 滑块组件 Slider({min: 0, // 最小值max: 350, // 最大值value: 30, // 当前值step:10, // 滑动步长style:SliderStyle.OutSet, // Inset 滑块的位置direction:Axis.Horizontal, // Verticalreverse:false // 是否反向滑动 }) style属性可以控制滑块在整个滑块…

【数值计算方法(黄明游)】解线性代数方程组的迭代法(一):向量、矩阵范数与谱半径【理论到程序】

文章目录 一、向量、矩阵范数与谱半径1、向量范数a. 定义及性质补充解释范数差 b. 常见的向量范数 l 1 l_1 l1​、 l 2 l_2 l2​、 l ∞ l_\infty l∞​ 范数性质关系 2、矩阵范数a. 矩阵的范数b. 常见的矩阵范数相容范数算子范数 3、谱半径4、知识点总结1. 向量范数2. 矩阵范数…

Dexie 查询sql速度优化

Dexie查询速度慢的原因主要一个优化点是复杂查询下的count执行。 以下摘自Dexie官方文档&#xff1a;https://dexie.org/docs/Collection/Collection.count() If executed on simple queries, the native IndexedDB ObjectStore count() method will be called (fast execution…

PPT插件-好用的插件-字距快速设置-大珩助手

字距快速设置 包含两端对齐、段首缩进、取消缩进、字间距、行间距、段后距 段首缩进 每次缩进两个字符&#xff0c;可对选中的文字、选中的多个文本对象两个层级操作 取消缩进 将缩进取消&#xff0c;可对选中的文字、选中的多个文本对象两个层级操作 字间距 预设了常用…

网页设计--第6次课后作业

试用Vue相关指令完成对以下json数据的显示。显示效果如下&#xff1a; 其中&#xff1a;gender1 显示为女&#xff0c;gender2显示为男。价格超过30元&#xff0c;显示“有点小贵”。价格少于等于30元&#xff0c;则显示“价格亲民”。 data: {books: [{"id": "…

【软件安装】VMware安装Centos7虚拟机并且设置静态IP,实现Windows和Centos7网络互相访问

这篇文章&#xff0c;主要介绍VMware安装Centos7虚拟机并且设置静态IP&#xff0c;实现Windows和Centos7网络互相访问。 目录 一、VMware安装Centos7 1.1、下载Centos7镜像 1.2、安装Centos7系统 二、设置静态IP地址 2.1、查看虚拟机网络IP 2.2、禁用NetworkManager服务 …

PandoraFMS 监控软件 SQL注入漏洞复现

0x01 产品简介 Pandora FMS是西班牙Artica公司的一套监控系统。该系统通过可视化的方式监控网络、服务器、虚拟基础架构和应用程序等。 0x02 漏洞概述 Pandora FMS监控软件存在SQL注入漏洞,攻击者通过chart_generator.php 来执行恶意语句,获取数据库敏感信息。 0x03 复现…

机器学习之全面了解回归学习器

我们将和大家一起探讨机器学习与数据科学的主题。 本文主要讨论大家针对回归学习器提出的问题。我将概要介绍&#xff0c;然后探讨以下五个问题&#xff1a; 1. 能否将回归学习器用于时序数据&#xff1f; 2. 该如何缩短训练时间&#xff1f; 3. 该如何解释不同模型的结果和…