EditText之自定義邊框顏色-創(chuàng)新互聯(lián)

EditText之自定義邊框顏色

創(chuàng)新互聯(lián)建站是一家集網(wǎng)站建設(shè),閔行企業(yè)網(wǎng)站建設(shè),閔行品牌網(wǎng)站建設(shè),網(wǎng)站定制,閔行網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,閔行網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。

有倆種方式可以達(dá)到效果

一種是網(wǎng)上比較推崇的用圖作背景,另一種則是自繪

圖作背景的:

 首先重新定義一個(gè)style。在values文件夾下新建一個(gè)style.xml文件:

      <?xml version="1.0" encoding="utf-8"?>

        <resources>

           <style name="my_edittext_style" parent="@android:style/Widget.EditText">

               <item name="android:background">@drawable/my_edittext</item>

           </style>

        </resources>

 接下來(lái)在drawable里添加my_edittext.xml:內(nèi)容如下

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true" android:drawable="@drawable/editbox_focus" />     <item android:drawable="@drawable/editbox_normal" />

</selector>

    其中editbox_normal為正常情況下的編輯框圖片,editbox_focus為選中下的編輯框圖片

 定義好了這兩個(gè)文件之后就可以用以下方式使用:

   <EditText

     android:text="My EditText"

     android:layout_width="fill_parent"

     android:layout_height="wrap_content">

   </EditText>

  以上用圖做背景的部分是引用http://blog.csdn.net/sinat_31998357/article/details/49491603里的

    PS:圖最好用九宮圖 這樣會(huì)自適應(yīng)的

自繪的方式:

  先自定義一個(gè)EditText:

     package com.MyView;

     import android.content.Context;

     import android.graphics.Canvas;

     import android.graphics.Color;

     import android.graphics.Paint;

     import android.graphics.RectF;

     import android.graphics.Paint.Style;

     import android.util.AttributeSet;

     import android.widget.EditText;

     public class MyEditText extends EditText{

        public MyEditText(Context context, AttributeSet attrs) {

           super(context, attrs);

        }

      @Override

      protected void onDraw(Canvas canvas) {

         Paint paint = new Paint();

         paint.setStyle(Style.STROKE);

         paint.setStrokeWidth(2);

         if(this.isFocused() == true)

             paint.setColor(Color.parseColor("#122e29"));

       else

            paint.setColor(Color.rgb(0,173,173));

       canvas.drawRoundRect(new RectF(2+this.getScrollX(), 2+this.getScrollY(), this.getWidth()-3+this.getScrollX(), this.getHeight()+ this.getScrollY()-1), 3,3, paint);

       super.onDraw(canvas);

    }

  }

xml里引用:

   <View

      android:id="@+id/view"

      android:focusable ="true"

      android:gravity="center"

      android:layout_x = "12dip"

      android:layout_y = "402dip"

      android:layout_width="104dip"

      android:layout_height="46dip"

      android:background = "#fffef9"

   />

   <com.MyView.MyEditText

      android:id="@+id/tv_state"

      android:focusable ="true"

      android:gravity="center"

      android:layout_x = "10dip"

      android:layout_y = "400dip"

      android:layout_width="110dip"

      android:layout_height="50dip"

      android:background = "#00000000"http://背景透明色

   />

弄一個(gè)View在EditText下面的目的是設(shè)置輸入框內(nèi)部顏色,如果直接設(shè)置EditText背景色的話,圓角矩形那不太好處理,如果在onDraw里畫(huà)背景色的話,這樣光標(biāo)就會(huì)不顯示,被遮住了

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

名稱欄目:EditText之自定義邊框顏色-創(chuàng)新互聯(lián)
鏈接分享:http://muchs.cn/article4/dchdie.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)ChatGPT、搜索引擎優(yōu)化、網(wǎng)站排名、虛擬主機(jī)外貿(mào)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司