国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁 > news >正文

佰聯(lián)軸承網(wǎng)做的網(wǎng)站網(wǎng)站seo優(yōu)化培訓(xùn)

佰聯(lián)軸承網(wǎng)做的網(wǎng)站,網(wǎng)站seo優(yōu)化培訓(xùn),做網(wǎng)站店鋪怎樣打理,項(xiàng)目建設(shè)管理費(fèi)一、背景及樣式效果 因項(xiàng)目需要,需要文本編輯時(shí),支持項(xiàng)目符號(hào)(無序列表)嘗試了BulletSpan,但不是很理想,并且考慮到影響老版本回顯等因素,最終決定自定義一個(gè)BulletEditText。 先看效果&…

一、背景及樣式效果? ? ??

因項(xiàng)目需要,需要文本編輯時(shí),支持項(xiàng)目符號(hào)(無序列表)嘗試了BulletSpan,但不是很理想,并且考慮到影響老版本回顯等因素,最終決定自定義一個(gè)BulletEditText。

? ? ? ? 先看效果:

????????

視頻效果

二、自定義View BulletEditText? ? ? ??

????????自定義控件BulletEditText源碼:

package com.ml512.widgetimport android.content.Context
import android.util.AttributeSet
import androidx.core.widget.doOnTextChanged/*** @Description: 簡單支持項(xiàng)目號(hào)的文本編輯器* @Author: Marlon* @CreateDate: 2024/2/1 17:44* @UpdateRemark: 更新說明:* @Version: 1.0*/
class BulletEditText : androidx.appcompat.widget.AppCompatEditText {/*** 是否開啟項(xiàng)目符號(hào)*/private var isNeedBullet: Boolean = false/*** 項(xiàng)目符號(hào)*/private var bulletPoint: String = "? "/*** 項(xiàng)目符號(hào)占用字符數(shù),方便設(shè)置光標(biāo)位置*/private var bulletOffsetIndex = bulletPoint.length/*** 相關(guān)監(jiān)聽回調(diào)*/private var editListener: EditListener? = nullconstructor(context: Context) : super(context)constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context,attrs,defStyleAttr)init {this.doOnTextChanged { text, start, before, count ->//如果是關(guān)閉狀態(tài)不做格式處理if (!isNeedBullet) {return@doOnTextChanged}if (count > before) {//處理項(xiàng)目號(hào)邏輯var offset = 0var tmp = text.toString()//連續(xù)回車去掉項(xiàng)目符號(hào)if (start >= bulletOffsetIndex && tmp.substring(start, start + count) == "\n") {val preSub = tmp.substring(start - bulletOffsetIndex, start)if (preSub == bulletPoint) {changeBulletState(false)tmp = tmp.replaceRange(start-bulletOffsetIndex, start + count, "")offset -= bulletOffsetIndex + 1setTextAndSelection(tmp, start + count + offset)return@doOnTextChanged}}//加入項(xiàng)目符號(hào)if (tmp.substring(start, start + count) == "\n") {changeBulletState(true)tmp = tmp.replaceRange(start, start + count, "\n$bulletPoint")offset += bulletOffsetIndexsetTextAndSelection(tmp, start + count + offset)}}}}override fun onSelectionChanged(selStart: Int, selEnd: Int) {super.onSelectionChanged(selStart, selEnd)//復(fù)制選擇時(shí)直接返回,關(guān)閉項(xiàng)目符號(hào)if (selStart != selEnd) {changeBulletState(false)return}//判斷當(dāng)前段落是否有項(xiàng)目號(hào),有開啟,沒有關(guān)閉val tmp = text.toString()val prefix = tmp.substring(0, selectionStart)if (prefix.isEmpty()) {changeBulletState(false)return}if (prefix.startsWith(bulletPoint) && !prefix.contains("\n")) {changeBulletState(true)return}val lastEnterIndex = prefix.lastIndexOf("\n")if (lastEnterIndex != -1 && lastEnterIndex + bulletOffsetIndex + 1 <= prefix.length) {val mathStr = prefix.substring(lastEnterIndex, lastEnterIndex + bulletOffsetIndex + 1)if (mathStr == "\n$bulletPoint") {changeBulletState(true)return}}changeBulletState(false)}/*** 更新bullet狀態(tài)*/private fun changeBulletState(isOpen: Boolean) {isNeedBullet = isOpeneditListener?.onBulletStateChange(isOpen)}/*** 設(shè)置是否開啟項(xiàng)目號(hào)*/fun setBullet(isOpen: Boolean) {isNeedBullet = isOpenval tmp = text.toString()var index = selectionStartvar prefix = tmp.substring(0, index)val suffix = tmp.substring(index)//加項(xiàng)目號(hào)if (isOpen) {//首個(gè)段落if (!prefix.contains("\n") && prefix.startsWith(bulletPoint)) {return}index += bulletOffsetIndexif (prefix.isEmpty() || (!prefix.contains("\n") && !prefix.startsWith(bulletPoint))) {setTextAndSelection("$bulletPoint$prefix$suffix", index)return}prefix = prefix.replaceLast("\n", "\n$bulletPoint")setTextAndSelection("$prefix$suffix", index)return}//去掉項(xiàng)目號(hào)if (prefix.startsWith(bulletPoint) && !prefix.contains("\n$bulletPoint")) {//首行邏輯index -= bulletOffsetIndexprefix = prefix.replaceLast(bulletPoint, "")setTextAndSelection("$prefix$suffix", index)return}if (prefix.contains("\n$bulletPoint")) {index -= bulletOffsetIndexprefix = prefix.replaceLast("\n$bulletPoint", "\n")setTextAndSelection("$prefix$suffix", index)}}/*** 設(shè)置文本及光標(biāo)位置*/private fun setTextAndSelection(text: String, index: Int) {setText(text)setSelection(index)}/*** 替換最后一個(gè)字符*/private fun String.replaceLast(oldValue: String, newValue: String): String {val lastIndex = lastIndexOf(oldValue)if (lastIndex == -1) {return this}val prefix = substring(0, lastIndex)val suffix = substring(lastIndex + oldValue.length)return "$prefix$newValue$suffix"}/*** 設(shè)置監(jiān)聽*/fun setEditListener(listener: EditListener) {editListener = listener}/*** 監(jiān)聽回調(diào)*/interface EditListener {/*** 項(xiàng)目符號(hào)開關(guān)狀態(tài)變化*/fun onBulletStateChange(isOpen: Boolean)}
}

三、調(diào)用

????????使用時(shí)一個(gè)項(xiàng)目符號(hào)的按鈕開關(guān)設(shè)置調(diào)用setBullet(isOpen: Boolean)?設(shè)置是否開啟項(xiàng)目符號(hào),同時(shí)實(shí)現(xiàn)一個(gè)setEditListener(listener: EditListener)根據(jù)光標(biāo)位置判斷當(dāng)前段落是否含有項(xiàng)目符號(hào),并回顯按鈕狀態(tài)。

 <com.ml512.widget.BulletEditTextandroid:id="@+id/etInput"android:layout_width="match_parent"android:layout_height="200dp"android:layout_below="@+id/tvTitle"android:layout_marginStart="15dp"android:layout_marginTop="15dp"android:layout_marginEnd="15dp"android:layout_marginBottom="15dp"android:autofillHints="no"android:background="@drawable/shape_edit_bg"android:gravity="top"android:hint="@string/text_please_input_some_worlds"android:inputType="textMultiLine"android:padding="15dp"android:textColor="@color/black"android:textColorHint="@color/color_FF_999999"android:textSize="16sp" />
        //點(diǎn)擊按鈕設(shè)置添加/取消項(xiàng)目符號(hào)tvBullet.setOnClickListener {tvBullet.isSelected = !tvBullet.isSelectedetInput.setBullet(tvBullet.isSelected)}//項(xiàng)目符號(hào)狀態(tài)監(jiān)聽,回顯到按鈕etInput.setEditListener(object :BulletEditText.EditListener{override fun onBulletStateChange(isOpen: Boolean) {tvBullet.isSelected = isOpen}})

大功告成!

http://m.aloenet.com.cn/news/1335.html

相關(guān)文章:

  • 地方網(wǎng)站域名選擇史上最強(qiáng)大的搜索神器
  • 網(wǎng)站建設(shè)這個(gè)口碑營銷的步驟
  • 在成都如何找到做網(wǎng)站的公司高級(jí)seo
  • 企業(yè)官方網(wǎng)站建設(shè)長沙專業(yè)競(jìng)價(jià)優(yōu)化首選
  • 自建網(wǎng)站網(wǎng)址臺(tái)州關(guān)鍵詞優(yōu)化推薦
  • 怎么建立網(wǎng)站網(wǎng)址360優(yōu)化大師官方網(wǎng)站
  • 公司網(wǎng)站怎么突然多了好多友情鏈接如何刪除今日熱搜前十名
  • 做se要明白網(wǎng)站小紅書關(guān)鍵詞排名怎么做
  • 做網(wǎng)站用不用thinkphpb2b電商平臺(tái)有哪些
  • 做網(wǎng)站價(jià)格公司神馬推廣
  • 珠海企業(yè)網(wǎng)站seo搜索優(yōu)化是什么
  • 電子商務(wù)網(wǎng)站建設(shè)商城網(wǎng)站長尾關(guān)鍵詞挖掘愛站工具
  • 網(wǎng)站vi設(shè)計(jì)公司惠州百度seo排名
  • 網(wǎng)站優(yōu)化設(shè)計(jì)方案怎么做青島運(yùn)營網(wǎng)絡(luò)推廣業(yè)務(wù)
  • 網(wǎng)站添加定位怎么做網(wǎng)站公司網(wǎng)站建設(shè)
  • 迅睿cms模板seo檢查工具
  • 網(wǎng)絡(luò)營銷網(wǎng)站建設(shè)論文百度網(wǎng)盤網(wǎng)頁版入口官網(wǎng)
  • 美國生物等效性如果做的網(wǎng)站如何制作網(wǎng)頁設(shè)計(jì)
  • 河北軟件開發(fā)網(wǎng)站建設(shè)如何創(chuàng)造一個(gè)自己的網(wǎng)站
  • 傳奇世界網(wǎng)頁版在線玩唐山seo優(yōu)化
  • flash網(wǎng)站建設(shè)技術(shù)成都網(wǎng)絡(luò)優(yōu)化托管公司
  • 各大網(wǎng)站代下單怎么做如何做好互聯(lián)網(wǎng)營銷
  • 怎樣維護(hù)公司網(wǎng)站百度搜索資源管理平臺(tái)
  • 做信息網(wǎng)站要辦icp證嗎如何刷seo關(guān)鍵詞排名
  • 虎門仿做網(wǎng)站網(wǎng)上推廣的平臺(tái)有哪些
  • 網(wǎng)站怎么做淘寶客網(wǎng)絡(luò)營銷的現(xiàn)狀及問題
  • 如何做學(xué)校網(wǎng)站產(chǎn)品軟文模板
  • 做彩票網(wǎng)站程序違法嗎寧波seo超級(jí)外鏈工具
  • 部門網(wǎng)站建設(shè)個(gè)人總結(jié)網(wǎng)站客服
  • 做婦產(chǎn)科網(wǎng)站優(yōu)化大師電視版