---
# System prepended metadata

title: '<font style="text-shadow:0px 0px 15px #FF37FD;">Paint</font>'
tags: [Kotlin, Android developer]

---

<font style="text-shadow:0px 0px 15px #FF37FD;">Paint</font>
===
###### tags: `Android developer` `Kotlin`
 <font color="Brown">android.graphics.Paint</font>
 
 <font color="Brown">關於如何繪製幾何圖形、文字、點陣圖、顏色訊息</font>
 
## <font color="sandybrown">Constructors</font>

### <font color="#990DFF">Paint()</font>
### <font color="#990DFF">Paint(flags: Int)</font>
### <font color="#990DFF">Paint(paint: Paint!)</font>

## <font color="sandybrown">Nested classes
</font>

### <font color="#990DFF">[Style](https://hackmd.io/-DnQh-ERS-CyNS2qPjQCsw?both)</font>


## <font color="sandybrown">常量</font>
### <font color="#990DFF">ANTI_ALIAS_FLAG</font>

:::info
繪製抗鋸齒
:::

:::warning

**Ex:**
```kotlin=
Paint(ANTI_ALIAS_FLAG)

Paint().flags=ANTI_ALIAS_FLAG
```
  
:::

## <font color="sandybrown">方法</font>
### <font color="#990DFF">setAntiAlias(aa: Boolean): Unit</font>

:::info
設置抗鋸齒
:::

:::warning

**Ex:**
```kotlin=
Paint().isAntiAlias = true
//等同
Paint(ANTI_ALIAS_FLAG)
Paint().flags=ANTI_ALIAS_FLAG
```
:::

### <font color="#990DFF">setColor(color: Int): Unit</font>

:::info
設置顏色
:::

:::warning

**Ex:**
```kotlin=
Paint().color = Color.RED
```
:::

### <font color="#990DFF">setStyle （style ： Paint.Style！）</font>

:::info
設置繪畫的樣式，用於控制如何解釋基元的幾何
:::

:::warning

**Ex:**
```kotlin=
Paint().style = Paint.Style.FILL            //填充內部
Paint().style = Paint.Style.FILL_AND_STROKE //填充內部還有描邊
Paint().style = Paint.Style.STROKE          //僅描邊
```
:::danger
**輸出結果 :**
![](https://i.imgur.com/jrAzzaF.png)
:::

:::success
FILL_AND_STROKE = FILL + STROKE 合成
:::

### <font color="#990DFF">setTextAlign(align: Paint.Align!): Unit</font>

:::info
設置 Paint 的文本對齊方式。它控製文本相對於其原點的定位方式。左對齊意味著所有文本都將被繪製到其原點的右側（即原點指定文本的左邊緣），依此類推。

:::

:::success
**參數**
align : 為 Paint 文本設置繪畫的“對齊”值。
:::

:::warning

**Ex:**
```kotlin=
Paint().textAlign=Paint.Align.LEFT           //靠左
Paint().textAlign=Paint.Align.CENTER         //置中
Paint().textAlign=Paint.Align.RIGHT          //靠右
```
:::danger
**輸出結果 :**
![](https://i.imgur.com/GjzyBuR.png)
:::

### <font color="#990DFF">setFakeBoldText(fakeBoldText: Boolean): Unit</font>

:::info
設置是否粗體

:::

:::success
**參數**
fakeBoldText : 如果在 paint 的標誌中設置fakeBoldText，則為true;如果為false，則為false。
:::

:::warning

**Ex:**
```kotlin=
val paint = Paint().apply {
            color=Color.RED
            style=Paint.Style.FILL
            strokeWidth=5f
            textSize=80f
            isFakeBoldText=true
        }
canvas?.drawText("isFakeBoldText",100f,200f,paint)
```
:::danger
**輸出結果 :**
![](https://i.imgur.com/QF3fvNw.png)
:::

### <font color="#990DFF">setUnderlineText(underlineText: Boolean): Unit</font>

:::info
設置是否有底線
:::

:::success
**參數**
underlineText : 如果設置paint的標誌中的underlineText位，則為true，false表示清除它。
:::

:::warning

**Ex:**
```kotlin=
val paint = Paint().apply {
            color=Color.RED
            style=Paint.Style.FILL
            strokeWidth=5f
            textSize=80f
            isUnderlineText=true
        }
canvas?.drawText("isUnderlineText",100f,200f,paint)
```
:::danger
**輸出結果 :**
![](https://i.imgur.com/07XqOX5.png)
:::

### <font color="#990DFF">setStrikeThruText(strikeThruText: Boolean): Unit</font>

:::info
設置是否有刪除線
:::

:::success
**參數**
strikeThruText : 如果在paint的標誌中設置strikeThruText，則為true，false為清除它。
:::

:::warning

**Ex:**
```kotlin=
val paint = Paint().apply {
            color=Color.RED
            style=Paint.Style.FILL
            strokeWidth=5f
            textSize=80f
            isStrikeThruText=true
        }
canvas?.drawText("isStrikeThruText",100f,200f,paint)
```
:::danger
**輸出結果 :**
![](https://i.imgur.com/ARvIPHB.png)
:::

### <font color="#990DFF">setTextSkewX(skewX: Float): Unit</font>

:::info
設置文字的 Paint 水平傾斜因子。默認值為0 ，負值向右傾斜，正值向左傾斜，對於近似斜文本，請使用-0.25左右的值。
:::

:::success
**參數**
skewX : 將繪製的傾斜因子設置為X以繪製文本。
:::

:::warning

**Ex:**
```kotlin=
val paint = Paint().apply {
            color=Color.RED
            style=Paint.Style.FILL
            strokeWidth=5f
            textSize=30f
        }
canvas?.drawText("正常傾斜",100f,200f,paint)
paint.textSkewX=-0.25f
canvas?.drawText("-0.25傾斜",100f,300f,paint)
paint.textSkewX=0.25f
canvas?.drawText("0.25傾斜",100f,400f,paint)
```
:::danger
**輸出結果 :**
![](https://i.imgur.com/n4bsxsn.png)
:::

### <font color="#990DFF">setTextSize(textSize: Float): Unit</font>

:::info
設置 Paint 的文字水平比例。默認值為1.0。值> 1.0將擴大文本範圍。值<1.0將使文本拉伸得更窄。
:::

:::success
**參數**
textSize : 將 Paint 的比例設置為X以繪製/測量文本。
:::

:::warning

**Ex:**
```kotlin=
val paint = Paint().apply {
            color=Color.RED
            style=Paint.Style.FILL
            strokeWidth=5f
            textSize=30f
        }
canvas?.drawText("正常拉伸",100f,200f,paint)
paint.textScaleX=2f
canvas?.drawText("放大拉伸",100f,300f,paint)
paint.textScaleX=0.5f
canvas?.drawText("縮小拉伸",100f,400f,paint)
```
:::danger
**輸出結果 :**
![](https://i.imgur.com/4NQ6TuG.png)
:::

### <font color="#990DFF">setTypeface(typeface: Typeface!): Typeface!</font>

:::info
設置或清除字體。
:::

:::success
**參數**
typeface : 可能是null。要在 Paint 設置的字體
:::

:::warning

**Ex:**
```kotlin=
val paint = Paint().apply {
            typeface = Typeface.SERIF
            typeface = Typeface.MONOSPACE
        }
```
:::
