<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                > 本節帶來Paint API系列的最后一個API,**Typeface(字型)**,由字義,我們大概可以猜到,這個 API是用來設置字體以及字體風格的,使用起來也非常的簡單!下面我們來學習下Typeface的一些相關 的用法! > > 官方API文檔:[Typeface](http://androiddoc.qiniudn.com/reference/android/graphics/Typeface.html)~ > > ![](https://box.kancloud.cn/2015-12-02_565e79994c69a.jpg) * * * ## 1.字體的可選風格 > 四個整型常量: > > * **BOLD**:加粗 > * **ITALIC**:斜體 > * **BOLD_ITALIC**:粗斜體 > * **NORMAL**:正常 * * * ## 2.可選字體對象(Typeface) > Android系統默認支持三種字體,分別為:**sans**,**serif**,**monospace**?而提供的可選靜態對象值有五個: > > * **DEFAULT**:默認正常字體對象 > * **DEFAULT_BOLD**:默認的字體對象,注意:這實際上不可能是粗體的,這取決于字體設置。 由getStyle()來確定 > * **MONOSPACE**:monospace 字體風格 > * **SANS_SERIF**:sans serif字體風格 > * **SERIF**:serif字體風格 * * * ## 3.自定義創建字型 > 可能默認的三種字體并不能滿足你,可能你喜歡MAC的字體——**Monaco字體**,你想讓你APP 里的文字可以用這種字體,首先準備好我們的TTF文件,然后丟到**assets/font/**目錄下 然后創建對應對象,關鍵代碼如下: > > **Typeface typeFace =Typeface.createFromAsset(getAssets(),"font/MONACO.ttf");** * * * ## 4.使用代碼示例: **運行效果圖**: ![](https://box.kancloud.cn/2015-12-02_565e79995a054.jpg) 自定義的View類:**MyView.java**: ~~~ /** * Created by Jay on 2015/11/5 0005. */ public class MyView extends View{ private Paint mPaint1,mPaint2,mPaint3,mPaint4,mPaint5; private Context mContext; public MyView(Context context) { this(context,null); } public MyView(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; init(); } public MyView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } private void init(){ mPaint1 = new Paint(); mPaint2 = new Paint(); mPaint3 = new Paint(); mPaint4 = new Paint(); mPaint5 = new Paint(); mPaint1.setColor(Color.RED); mPaint2.setColor(Color.BLUE); mPaint3.setColor(Color.BLACK); mPaint4.setColor(Color.YELLOW); mPaint5.setColor(Color.GRAY); mPaint1.setTextSize(100); mPaint2.setTextSize(100); mPaint3.setTextSize(100); mPaint4.setTextSize(100); mPaint5.setTextSize(100); mPaint1.setTypeface(Typeface.DEFAULT_BOLD); mPaint2.setTypeface(Typeface.MONOSPACE); mPaint3.setTypeface(Typeface.SANS_SERIF); mPaint4.setTypeface(Typeface.SERIF); mPaint5.setTypeface(Typeface.createFromAsset(mContext.getAssets(), "font/MONACO.ttf")); } @Override protected void onDraw(Canvas canvas) { canvas.drawText("Coder-pig", 100, 100, mPaint1); canvas.drawText("Coder-pig", 100, 200, mPaint2); canvas.drawText("Coder-pig", 100, 300, mPaint3); canvas.drawText("Coder-pig", 100, 400, mPaint4); canvas.drawText("Coder-pig", 100, 500, mPaint5); } } ~~~ 恩呢,非常簡單~就不解釋了,要字體的可以自己百度或者下載示例代碼~ * * * ## 本節示例代碼下載: [TypefaceDemo.zip](http://static.runoob.com/download/TypefaceDemo.zip) * * * ## 本節小結: > 好的,一連十幾節的Paint API詳解就到這里了,應該已經涵蓋大部分的可能會用到的API了, 不知道你都Get了沒,這些都是為我們進階部分的自定義控件做鋪墊~嗯,就說這么多,謝謝~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看