重拾Android之路之EditText


引言

EditTexAndroid中比較常用的一個(gè)控件,可以說它是用戶和Android應(yīng)用進(jìn)行數(shù)據(jù)傳遞的通道.通過它,用戶可以把數(shù)據(jù)傳給App,然后我們可以獲取到用戶輸入的數(shù)據(jù).

EditTextTextView的子類,它繼承了TextView的所有屬性.在實(shí)際開發(fā)中我們可能會(huì)根據(jù)開發(fā)需求,自定義出比較美觀的EditText控件,這里我們不說自定義EditText.主要說一下EditText使用中的細(xì)節(jié).以及使用EditText過程中遇到的坑...


正文

EditText屬性(API 24)
  • android:hint //設(shè)置hint提示文本
  • android:textColorHint //設(shè)置hint提示文字顏色
  • android:textColor //設(shè)置文字顏色
  • android:textSize //設(shè)置文本字體大小
  • android:textStyle //設(shè)置文本字體樣式,bold(加粗),italic(傾斜),normal(默認(rèn)是正常字體).
  • android:numeric //控制EditText輸入數(shù)字的類型 decimal(浮點(diǎn)數(shù)),integer(正整數(shù)),signed(帶+ -號(hào)的整數(shù)).注意:該屬性在使用時(shí)提示已過時(shí),建議使用android:inputType屬性替代.
  • android:singleLine //設(shè)置是否單行輸入 true(單行輸入),false(會(huì)自動(dòng)換行).注意:該屬性在使用時(shí)提示已過時(shí),建議使用android:maxLines="1"屬性替代.
  • android:password="true" //以密文的形式顯示輸入的文本.注意:該屬性在使用時(shí)提示已過時(shí),建議使用android:inputType屬性替代.
  • android:textAlignment //設(shè)置EditText中文本顯示的位置,center(居中),inherit(默認(rèn),居左邊顯示),viewStart(居左顯示),viewEnd(居右顯示),textStart(居左顯示),textEnd(居右顯示).這里需要注意的是最低支持的API版本是17,前兩個(gè)可以在API14中使用,而后面使用就會(huì)報(bào)紅線...
  • android:textColorHighlight //設(shè)置被選中字體的顏色.默認(rèn)為 Theme 主題中的 “colorAccent”的顏色.
  • textCursorDrawable //設(shè)置被光標(biāo)的顏色.默認(rèn)為 Theme 主題中的 “colorAccent”的顏色.
  • android:textScaleX //設(shè)置文本的水平縮放系數(shù).
  • android:typeface //設(shè)置hint提示文本的字體.normal(默認(rèn)),monospace,sans,serif.這里就不解釋了,大家試一下就能看出效果.
  • android:background //設(shè)置EditText背景."@null"設(shè)置背景為透明.當(dāng)我們設(shè)置背景后,EditText的那條線就會(huì)消失.
  • android:textAppearance //設(shè)置文本的顏色,字體,大小和樣式.
  • android:digits //設(shè)置只接收指定的文本內(nèi)容.
  • android:phoneNumber="true" //設(shè)置輸入電話號(hào)碼.注意:該屬性在使用時(shí)提示已過時(shí),建議使用android:inputType屬性替代.
  • android:editable //設(shè)置EditText是否可以編輯.當(dāng)你設(shè)置為true,會(huì)提示你該EditText已經(jīng)是可編輯的.設(shè)置為false時(shí)會(huì)提示使用inputType替代.
  • android:inputType //設(shè)置文本的類型,用于幫助輸入法顯示合適的鍵盤類型.
  • android:maxLength //設(shè)置EditText最多接受的文本的個(gè)數(shù).
  • android:lines //設(shè)置EditText顯示的行數(shù),設(shè)置兩行就顯示兩行,即使第二行沒有數(shù)據(jù).
  • android:lineSpacingExtra //設(shè)置行間距.
  • android:lineSpacingMultiplier //設(shè)置行間距的倍數(shù). 如設(shè)置成1.5倍.
  • android:imeOptions //設(shè)置右下角IME動(dòng)作與編輯框相關(guān)的動(dòng)作,如actionDone右下角將顯示一個(gè)“完成”,而不設(shè)置默認(rèn)是一個(gè)回車符號(hào).下面會(huì)詳細(xì)說明.
使用細(xì)節(jié)

我們在使用EditText中有時(shí)候會(huì)限制輸入框中輸入的文本類型,或者當(dāng)彈出軟鍵盤時(shí),出現(xiàn)的是比較合適的輸入法.如:我們在QQ時(shí),彈出的軟件盤顯示的就是數(shù)字,當(dāng)輸入密碼時(shí),右下角編輯框顯示的是"完成",點(diǎn)擊即會(huì)關(guān)閉軟鍵盤.其實(shí)這也就是inputTypeimeOptions屬性來實(shí)現(xiàn)的, inputType屬性可以指定鍵盤的類型,而imeOptions指定鍵盤右下角顯示的Action.下面我們就來實(shí)現(xiàn)EditText使用過程中的小細(xì)節(jié).

  1. 這個(gè)類似QQ登錄輸入框,第一個(gè)EditText(用戶名)的inputType設(shè)置的是text,imeOptions設(shè)置的是actionNext(下一個(gè)).第二個(gè)EditText(密碼)的inputType設(shè)置的是textPassword,imeOptions設(shè)置的是actionDone(完成).當(dāng)輸入完用戶名,點(diǎn)擊鍵盤action下一個(gè),會(huì)跳到密碼輸入框,當(dāng)輸入完密碼后,點(diǎn)擊鍵盤action完成,軟鍵盤就會(huì)隱藏.來看下效果圖就明白來.

Xml布局:

<EditText
     android:id="@+id/et_user_name"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:hint="請輸入用戶名..."
     android:imeOptions="actionNext"
     android:inputType="text"
     android:textColor="@color/black" />

 <EditText
     android:id="@+id/et_password"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:hint="請輸入密碼..."
     android:imeOptions="actionDone"
     android:inputType="textPassword"
     android:textColor="@color/black" />

注意:這里需要注意的是,如果想讓鍵盤顯示Action,需要inputTypeimeOptions結(jié)合使用才可以,只使用imeOptions是不會(huì)有效果的.只會(huì)顯示默認(rèn)的換行action.(不同手機(jī)的輸入法不一樣,可能顯示的會(huì)有點(diǎn)小差別)

  1. 接下來我們看一下inputType可以接受的參數(shù):

我們可以使用android:inputType屬性指定要用于EditText對象的鍵盤類型.例如,如果你希望用戶輸入電子郵件地址,則應(yīng)使用textEmailAddress輸入類型.以下是輸入類型常見的值:

  • "text" 普通文本鍵盤
  • "textEmailAddress" 帶有@字符的普通文本鍵盤
  • "textUri" 帶有/字符的普通文本鍵盤.
  • "number" 基本數(shù)字鍵盤.
  • "phone" 電話樣式鍵盤.
  • "datetime" 時(shí)間日期.
  • "date" 日期.

android:inputType還允許指定某些鍵盤行為,例如是否大寫所有新單詞或使用自動(dòng)完成和拼寫建議等功能.以下是定義鍵盤行為的一些常見輸入類型值:

  • "textCapSentences" 普通的文本鍵盤,大寫每個(gè)新句子的第一個(gè)字母.
  • "textCapWords" 大寫每個(gè)單詞的正常文本鍵盤.適合標(biāo)題或人名.
  • "textAutoCorrect" 正常文本鍵盤,可糾正拼寫錯(cuò)誤的字詞.
  • "textPassword" 這個(gè)就和設(shè)置password="true"是一樣的效果.以原點(diǎn)的形式顯示輸入的文本.
  • "textMultiLine" 普通文本鍵盤,允許用戶輸入包含換行符的長字符串(回車符).
  1. 上面演示第一個(gè)小栗子時(shí),說了當(dāng)需要指定鍵盤action時(shí),需要和inputType結(jié)合使用才會(huì)有效果,下面就來看下imeOptions可以接受的參數(shù):下面直接來張圖,大家一看就明白了.上圖....

在代碼中我們可以響應(yīng)action操作的事件.如xml布局中有一個(gè)id為search的EditText控件,并指定imeOptions="actionSearch",我們可以指定action操作的事件.

 EditText editText = (EditText) findViewById(R.id.search);
 editText.setOnEditorActionListener(new OnEditorActionListener() { 
 @Override 
 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
     boolean handled = false;
     if (actionId == EditorInfo.IME_ACTION_SEND) {
         Toast.makeText(this, "點(diǎn)擊actionSearch執(zhí)行的操作 ", Toast.LENGTH_SHORT).show(); 
         handled = true;
     } 
     return handled;
 } 
 });

注意:再次提醒,在使用imeOptions時(shí),如果你沒有使用inputType屬性,是不會(huì)有效果的.

  1. 最后一個(gè)就是使用EditText中遇到的坑了....相信大多數(shù)開發(fā)者都遇到過,那就是當(dāng)你的EditText輸入框在屏幕的下方時(shí),彈出軟鍵盤會(huì)遮擋住輸入框...當(dāng)然,你可以使用ScrollView嵌套EditText來解決這一問題.但我最近看到一篇文章,感覺很優(yōu)雅的就解決了這個(gè)問題.下面貼出文章地址.軟鍵盤擋住輸入框問題的終極解決方案.
EditText屬性大全(重新收錄)

EditText繼承關(guān)系View-->TextView-->EditText

  • android:hint="請輸入數(shù)字!"
    設(shè)置顯示在控件上的提示信息

  • android:numeric="integer"
    設(shè)置只能輸入整數(shù),如果是小數(shù)則是:decimal

  • android:singleLine="true"
    設(shè)置單行輸入,一旦設(shè)置為true,則文字不會(huì)自動(dòng)換行。被android:maxLines="1"所代替了。

  • android:textColor = "#ff8c00"
    字體顏色

  • android:textStyle="bold"
    字體,bold, italic, bolditalic

  • android:textSize="18sp"
    大小

  • android:capitalize = "characters"
    以大寫字母寫

  • android:textAlign="center"
    EditText沒有這個(gè)屬性,但TextView有,居中

  • android:textColorHighlight="#cccccc"
    被選中文字的底色,默認(rèn)為藍(lán)色

  • android:textColorHint="#ffff00"
    設(shè)置提示信息文字的顏色,默認(rèn)為灰色

  • android:textScaleX="1.5"
    控制字與字之間的間距

  • android:typeface="monospace"
    字型,normal, sans, serif, monospace

  • android:background="@null"
    背景,這里沒有,指透明

  • android:layout_weight="1"
    權(quán)重,控制控件之間的地位,在控制控件顯示的大小時(shí)蠻有用的。

  • android:textAppearance="?android:attr/textAppearanceLargeInverse"
    文字外觀,這里引用的系統(tǒng)自帶的一個(gè)外觀,?表示系統(tǒng)是否有這種外觀,否則使用默認(rèn)的外觀,可設(shè)置的值如下:
    textAppearanceButton/textAppearanceInverse/textAppearanceLarge/textAppearanceLargeInverse/textAppearanceMedium/textAppearanceMediumInverse。

  • android:layout_gravity="center_vertical"
    設(shè)置控件顯示的位置:默認(rèn)top,這里居中顯示

  • et.setSelection(et.length());
    調(diào)整光標(biāo)到最后一行

  • android:autoText
    自動(dòng)拼寫幫助

  • android:autoLink=”all”
    設(shè)置是否當(dāng)文本為URL鏈接/email/電話號(hào)碼/map時(shí),文本顯示為可點(diǎn)擊的鏈接??蛇x值(none/web/email/phone/map/all)

  • android:cursorVisible
    設(shè)定光標(biāo)為顯示/隱藏,默認(rèn)顯示。

  • android:digits
    設(shè)置允許輸入哪些字符。如“1234567890.+-*/% ()”

  • android:drawableBottom
    在text的下方輸出一個(gè)drawable,如圖片。如果指定一個(gè)顏色的話會(huì)把text的背景設(shè)為該顏色,并且同時(shí)和background使用時(shí)覆蓋后者。

  • android:drawableLeft
    在text的左邊輸出一個(gè)drawable,如圖片。

  • android:drawablePadding
    設(shè)置text與drawable(圖片)的間隔,與drawableLeft、drawableRight、drawableTop、drawableBottom一起使用,可設(shè)置為負(fù)數(shù),單獨(dú)使用沒有效果。

  • android:drawableRight
    在text的右邊輸出一個(gè)drawable,如圖片。

  • android:drawableTop
    在text的正上方輸出一個(gè)drawable,如圖片。

  • android:ellipsize
    設(shè)置當(dāng)文字過長時(shí),該控件該如何顯示。有如下值設(shè)置:
    ”start”—?省略號(hào)顯示在開頭;
    ”end”——省略號(hào)顯示在結(jié)尾;
    ”middle”—-省略號(hào)顯示在中間;
    ”marquee” ——以跑馬燈的方式顯示(動(dòng)畫橫向移動(dòng)); 自己測的時(shí)候,好像xml報(bào)錯(cuò)

  • android:gravity
    設(shè)置文本位置,如設(shè)置成“center”,文本將居中顯示。

  • android:imeOptions
    附加功能,設(shè)置右下角IME動(dòng)作與編輯框相關(guān)的動(dòng)作,如actionDone右下角將顯示一個(gè)“完成”,而不設(shè)置默認(rèn)是一個(gè)回車符號(hào)。

  • android:imeActionId
    設(shè)置IME動(dòng)作ID。

  • android:includeFontPadding
    設(shè)置文本是否包含頂部和底部額外空白,默認(rèn)為true。

  • android:inputMethod
    為文本指定輸入法,需要完全限定名(完整的包名)。例如:
    com.google.android.inputmethod.pinyin

  • android:linksClickable
    設(shè)置鏈接是否點(diǎn)擊連接,即使設(shè)置了autoLink。

  • android:ems
    設(shè)置TextView的寬度為N個(gè)字符的寬度。這里測試為一個(gè)漢字字符寬度,android:maxEms設(shè)置TextView的寬度為最長為N個(gè)字符的寬度。與ems同時(shí)使用時(shí)覆蓋ems選項(xiàng)。android:minEms設(shè)置TextView的寬度為最短為N個(gè)字符的寬度。與ems同時(shí)使用時(shí)覆蓋ems選項(xiàng)。

  • android:maxLength
    限制顯示的文本長度,超出部分不顯示。

  • android:scrollHorizontally
    設(shè)置文本超出TextView的寬度的情況下,是否出現(xiàn)橫拉條。

  • android:shadowRadius
    設(shè)置陰影的半徑。設(shè)置為0.1就變成字體的顏色了,一般設(shè)置為3.0的效果比較好。

  • android:shadowColor
    指定文本陰影的顏色,需要與shadowRadius一起使用。

  • android:shadowDx
    設(shè)置陰影橫向坐標(biāo)開始位置

  • android:shadowDy
    設(shè)置陰影縱向坐標(biāo)開始位置。

  • android:typeface
    設(shè)置文本字體,必須是以下常量值之一:normal 0, sans 1, serif 2, monospace(等寬字體) 3

  • android:maxHeight
    設(shè)置文本區(qū)域的最大高度

  • android:minHeight
    設(shè)置文本區(qū)域的最小高度

簡單示例:

演示效果:

涉及到關(guān)于EditText的問題

1.怎樣改變EditText樣式(去下劃線 圓滑矩形片框 背景顏色等)

2.EditText光標(biāo)顯示位置,顏色,高度等

源碼展示

1.通過背景這一屬性設(shè)置EditText圓滑片框,片框顏色,背景顏色

drawable下創(chuàng)建et.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
            <solid
                android:color="#FFFFFF"/>
            <corners
                android:bottomRightRadius="5dip"
                android:bottomLeftRadius="5dip"
                android:topLeftRadius="5dip"
                android:topRightRadius="5dip"/>
            <stroke
                android:width="0.5px"
                android:color="#505050"/>
        </shape>
    </item>
</layer-list>

屬性可以根據(jù)要求改

2.activity.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <TextView android:text="登錄" android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/textView_1" />
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#C6C7C7"
        android:layout_below="@+id/textView_1"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/view"></View>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/editText"
        android:paddingLeft="20dp"
        android:hint="用戶名/郵箱/手機(jī)號(hào)"
        android:textCursorDrawable="@null"

        android:background="@drawable/et"
        android:layout_below="@+id/view"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/editText2"
        android:background="@drawable/et"
        android:paddingLeft="20dp"
        android:hint="請輸入密碼:"
        android:layout_below="@+id/editText"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:id="@+id/editText3"
        android:paddingLeft="20dp"
        android:hint="請輸入驗(yàn)證碼:"
        android:background="@drawable/et"
        android:layout_below="@+id/editText2"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="20dp"
        android:layout_alignRight="@+id/textView_1"
        android:layout_alignEnd="@+id/textView_1" />

    <EditText
        android:layout_width="140dp"
        android:layout_height="50dp"
        android:background="@drawable/et"
        android:id="@+id/editText4"
        android:layout_alignBottom="@+id/editText3"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="登錄"
        android:editable="false"
        android:textColor="#FFFFFF"
        android:gravity="center"
        android:background="@drawable/et1"
        android:id="@+id/editText5"
        android:layout_below="@+id/editText3"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:text="免費(fèi)注冊"
        android:textColor="#F98498"
        android:gravity="center"
        android:id="@+id/textView"
        android:layout_below="@+id/editText5"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:text="忘記密碼?"
        android:textColor="#77B1F3"
        android:gravity="center"
        android:id="@+id/textView2"
        android:layout_below="@+id/editText5"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />
</RelativeLayout>

3.關(guān)于光標(biāo)設(shè)置

(1)使光標(biāo)移動(dòng)到制定的位置:editText.setSelection(2);(輸入的參數(shù)是個(gè)整數(shù))

(2)在請求出現(xiàn)光標(biāo)時(shí),也就是在獲取焦點(diǎn)時(shí):editText.requestFocus();
清除光標(biāo),也就是失去焦點(diǎn):editText.clearFocus();

(3)讓EditText不出現(xiàn)光標(biāo):editText.setCursorVisible(false);

也可以屬性中修改android:cursorVisible及是否顯示光標(biāo)

(4)光標(biāo)顏色:android:textCursorDrawable="@null"與字體同色

(5)自定義光標(biāo)樣式:

<EditText  
android:layout_width="match_parent"  
android:layout_height="wrap_content"  
android:textCursorDrawable="@drawable/color_cursor"/>  
樣式文件:  
<?xml version="1.0" encoding="utf-8"?>    
<shape xmlns:android="http://schemas.android.com/apk/res/android"    
    android:shape="rectangle">    
    <size android:width="1dp" />  
    <solid android:color="#000000"  />  
</shape>    

edittext 下劃線顏色更改的問題:

styles里apptheme(app主題)加上
<item name="colorAccent">@color/primary_blue(其他顏色也行)</item>

或者:

在styles.xml文件中聲明自定義樣式

<style name="MyEditText" parent="Theme.AppCompat.Light"> 
 <item name="colorControlNormal">@color/indigo</item> 
 <item name="colorControlActivated">@color/pink</item>
</style>

通過android:theme屬性將此樣式應(yīng)用于您的EditText

<EditText 
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:hint="Hint text"
 android:theme="@style/MyEditText"/>

效果如下:


監(jiān)聽EditText的變化

使用EditTextaddTextChangedListener(TextWatcher watcher)方法對EditText實(shí)現(xiàn)監(jiān)聽,TextWatcher是一個(gè)接口類,所以必須實(shí)現(xiàn)TextWatcher里的抽象方法:

et.addTextChangedListener(new TextWatcher() {  

            @Override 
            public void beforeTextChanged(CharSequence s, int start, int count,  
                    int after) {  
                tv.setText("還能輸入"+Rest_Length+"個(gè)字");              
            }  

            @Override 
            public void afterTextChanged(Editable s) {  
                tv.setText("還能輸入"+Rest_Length+"個(gè)字");  
            }  

            @Override 
            public void onTextChanged(CharSequence s, int start, int before, int count) {  
                if(Rest_Length>0){  
                    Rest_Length = MAX_LENGTH - et.getText().length();  
                }  
            }             
        });  

        clearBtn.setOnClickListener(new Button.OnClickListener() {        
            @Override 
            public void onClick(View v) {  
                et.setText("");  
                Rest_Length = MAX_LENGTH;  
            }  
        });  
    }

現(xiàn)在有個(gè)小需求,需要輸入11位手機(jī)號(hào)碼,但是需要在第三位和第四位之間加上空格,第七位和第八位中間加上空格

效果如下:

貼上代碼:

        editTextPhone.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                L.i("start :" + start);
                if ((start == 3 || start == 8) && (tempLength < s.length())) {
                    s = s.subSequence(0, s.length() - 1) + " " + s.charAt(s.length() - 1);
                    editTextPhone.setText(s);
                    editTextPhone.setSelection(s.length());
                    L.i("start1 :" + start);
                } else if ((start == 4 || start == 9) && (tempLength > s.length())) {
                    s = s.subSequence(0, s.length() - 1);
                    editTextPhone.setText(s);
                    editTextPhone.setSelection(s.length());
                    L.i("start2 :" + start);
                }

                if ((start == 12) && (tempLength < s.length())) {
                    buttonNext.setEnabled(true);
                } else {
                    buttonNext.setEnabled(false);
                }
                tempLength = s.length();
            }

            @Override
            public void afterTextChanged(Editable s) {
            }
        });

注意:1.如果直接用editTextPhone.setText(s);沒有editTextPhone.setSelection(s.length());這段代碼的話,光標(biāo)會(huì)回到初始位置0,因此,要將光標(biāo)移至當(dāng)前最末位。另外,(起始位置為0)在位置為3的時(shí)候,好理解,意味著第三個(gè)數(shù)字輸入中狀態(tài)時(shí)添加空格。后面的位置注意是8,并不是7,因?yàn)榭崭褚呀?jīng)被添加進(jìn)去了,因此要往后移一位。往回刪的時(shí)候,刪除的位置就不能再是原先的位置3和位置8了,而應(yīng)該是他們的各自后一位,位置4和位置9。判斷是輸入還是刪除狀態(tài),比較簡單,判斷tempLength與當(dāng)前Sequence s.length()的大小即可。

還有一點(diǎn),在輸入位置12時(shí),start==12,當(dāng)刪除當(dāng)前位置12時(shí),start還是==12,因此要多加輸入/刪除的判斷。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容