|
1 | 1 | # 关于属性适配的问题
|
2 | 2 |
|
3 |
| -* 你好,如果你是刚使用这个库的人可以不必理会,如果你之前使用了 `TitleBar` 这个库,也就是 5.0 版本以下的,在升级到 `5.0` 版本后需要进行适配,否则 `Android Studio` 会报错`编译不通过`,对于这个问题我表示十分抱歉,低版本的 `xml` 属性命名得并不是很规范,现在在 `5.0` 版本给予了纠正,尽管这次的代价比较大,但是我会义无反顾去做,如果你使用了 `TitleBar` 但是不想进行适配,请不要`升级`依赖版本。 |
| 3 | +* 你好,如果你是刚使用这个库的人可以不必理会,如果你之前使用了 `TitleBar` 这个库,也就是 `9.0` 版本以下的,在升级到 `9.0` 版本后需要进行适配,否则 `Android Studio` 会报错`编译不通过`,对于这个问题我表示十分抱歉,低版本的 `xml` 属性命名得并不是很规范,现在在 `5.0` 和 `9.0` 版本进行优化,尽管这次的代价比较大,但是我会义无反顾去做,如果你使用了 `TitleBar` 但是不想进行适配,请不要`升级`依赖库版本。 |
4 | 4 |
|
5 |
| -#### 3.5 版本属性命名 |
| 5 | +#### 从 5.0 以上的版本升级到 9.0 版本适配方案 |
| 6 | + |
| 7 | +* 删除 `app:backButton` 属性,请使用 `app:leftIcon` 代替,全局替换如下: |
| 8 | + |
| 9 | +```text |
| 10 | +// 旧版本的用法 |
| 11 | +app:backButton="false" |
| 12 | +// 新版本的用法 |
| 13 | +app:leftIcon="@null" |
| 14 | +``` |
| 15 | + |
| 16 | +* 拆分 `android:drawablePadding` 属性,将原有属性拆分为以下几个属性: |
| 17 | + |
| 18 | +```text |
| 19 | +app:titleIconPadding |
| 20 | +
|
| 21 | +app:leftIconPadding |
| 22 | +
|
| 23 | +app:rightIconPadding |
| 24 | +``` |
| 25 | + |
| 26 | +* 拆分 `android:drawableSize` 属性,将原有属性拆分为以下几个属性: |
| 27 | + |
| 28 | +```text |
| 29 | +app:titleIconWidth |
| 30 | +app:titleIconHeight |
| 31 | +
|
| 32 | +app:leftIconWidth |
| 33 | +app:leftIconHeight |
| 34 | +
|
| 35 | +app:rightIconWidth |
| 36 | +app:rightIconHeight |
| 37 | +``` |
| 38 | + |
| 39 | +* 属性改名一览,只是简单改名,没有做太多修改: |
| 40 | + |
| 41 | +| 5.0 版本 | 9.0 版本 | |
| 42 | +| :------------: | :-------------: | |
| 43 | +| `app:leftSize` | `app:leftTitleSize` | |
| 44 | +| `app:rightSize` | `app:rightTitleSize` | |
| 45 | +| `app:leftColor` | `app:leftTitleColor` | |
| 46 | +| `app:rightColor` | `app:rightTitleColor` | |
| 47 | +| `app:leftTint` | `app:leftIconTint` | |
| 48 | +| `app:rightTint` | `app:rightIconTint` | |
| 49 | +| `app:lineColor` | `app:lineDrawable` | |
| 50 | +| `android:paddingVertical` | `app:childPaddingVertical` | |
| 51 | +| `android:paddingHorizontal` | `app:childPaddingHorizontal` | |
| 52 | + |
| 53 | +* 新增左标提和右标题的文本样式设置(之前的版本只有中间标题的): |
| 54 | + |
| 55 | +```text |
| 56 | +app:leftTitleStyle |
| 57 | +app:rightTitleStyle |
| 58 | +``` |
| 59 | + |
| 60 | +* 新增中间标题图标设置(之前的版本只有左标题和右标题才有): |
| 61 | + |
| 62 | +```text |
| 63 | +app:titleIcon |
| 64 | +app:titleIconPadding |
| 65 | +app:titleIconTint |
| 66 | +``` |
| 67 | + |
| 68 | +* 新增图标的显示重心设置(图标在文字的哪个位置上面绘制): |
| 69 | + |
| 70 | +```text |
| 71 | +app:titleIconGravity |
| 72 | +app:leftIconGravity |
| 73 | +app:rightIconGravity |
| 74 | +``` |
| 75 | + |
| 76 | +#### 从 1.5 以上的版本升级到 5.0 版本适配方案 |
| 77 | + |
| 78 | +* 常规适配:单词反向,不再采用下划线形式,而用单词开头大写的方式代替 |
| 79 | + |
| 80 | +| 3.5 版本 | 5.0 版本 | |
| 81 | +| :------------: | :-------------: | |
| 82 | +| title_left | leftTitle | |
| 83 | +| title_right | rightTitle | |
| 84 | +| icon_left | leftIcon | |
| 85 | +| icon_right | rightIcon | |
| 86 | +| color_title | titleColor | |
| 87 | +| color_right | rightColor | |
| 88 | +| color_left | leftColor | |
| 89 | +| size_title | titleSize | |
| 90 | +| size_right | rightSize | |
| 91 | +| size_left | leftSize | |
| 92 | +| background_left | leftBackground | |
| 93 | +| background_right| rightBackground | |
| 94 | + |
| 95 | +* 特殊适配:去除下划线,并且用单词开头大写的方式代替 |
| 96 | + |
| 97 | +| 3.5 版本 | 5.0 版本 | |
| 98 | +| :-------: | :---------: | |
| 99 | +| bar_style | barStyle | |
| 100 | +| line_visible | lineVisible | |
| 101 | +| line_color | lineColor | |
| 102 | +| line_size | lineSize | |
| 103 | + |
| 104 | +* 极端适配:命名和之前完全不同 |
| 105 | + |
| 106 | +| 3.5 版本 | 5.0 版本 | |
| 107 | +| :-------: | :-------: | |
| 108 | +| icon_back | backButton | |
| 109 | + |
| 110 | +* 无需适配:这个属性没有任何改动 |
| 111 | + |
| 112 | +| 3.5 版本 | 5.0 版本 | |
| 113 | +| :-----: | :-------: | |
| 114 | +| title | title | |
| 115 | + |
| 116 | +#### 不同版本的 XML 属性命名预览 |
| 117 | + |
| 118 | +* 3.5 版本 XML 属性命名 |
6 | 119 |
|
7 | 120 | ```xml
|
8 | 121 | <declare-styleable name="TitleBar">
|
|
39 | 152 | </declare-styleable>
|
40 | 153 | ```
|
41 | 154 |
|
42 |
| -#### 5.0 版本属性命名 |
| 155 | +* 5.0 版本 XML 属性命名 |
43 | 156 |
|
44 | 157 | ```xml
|
45 |
| -<declare-styleable name="TitleBar" tools:ignore="ResourceName"> |
| 158 | +<declare-styleable name="TitleBar"> |
46 | 159 | <!-- 整体样式 -->
|
47 | 160 | <attr name="barStyle">
|
48 | 161 | <enum name="light" value="0x10" />
|
|
73 | 186 | </declare-styleable>
|
74 | 187 | ```
|
75 | 188 |
|
76 |
| -#### 适配方案 |
| 189 | +* 9.0 版本 XML 属性命名 |
77 | 190 |
|
78 |
| -* 常规适配:单词反向,不再采用下划线形式,而用单词开头大写的方式代替 |
| 191 | +```xml |
| 192 | +<declare-styleable name="TitleBar"> |
79 | 193 |
|
80 |
| -| 3.5 版本 | 5.0 版本 |
81 |
| -| :------------: | :-------------: | |
82 |
| -| title_left | leftTitle | |
83 |
| -| title_right | rightTitle | |
84 |
| -| icon_left | leftIcon | |
85 |
| -| icon_right | rightIcon | |
86 |
| -| color_title | titleColor | |
87 |
| -| color_right | rightColor | |
88 |
| -| color_left | leftColor | |
89 |
| -| size_title | titleSize | |
90 |
| -| size_right | rightSize | |
91 |
| -| size_left | leftSize | |
92 |
| -| background_left | leftBackground | |
93 |
| -| background_right| rightBackground | |
| 194 | + <!-- 标题栏背景 --> |
| 195 | + <attr name="android:background" /> |
94 | 196 |
|
95 |
| -* 特殊适配:去除下划线,并且用单词开头大写的方式代替 |
| 197 | + <!-- 标题栏样式 --> |
| 198 | + <attr name="barStyle"> |
| 199 | + <enum name="light" value="0x10" /> |
| 200 | + <enum name="night" value="0x20" /> |
| 201 | + <enum name="transparent" value="0x30" /> |
| 202 | + <enum name="ripple" value="0x40" /> |
| 203 | + </attr> |
96 | 204 |
|
97 |
| -| 3.5 版本 | 5.0 版本 | |
98 |
| -| :-------: | :---------: | |
99 |
| -| bar_style | barStyle | |
100 |
| -| line_visible | lineVisible | |
101 |
| -| line_color | lineColor | |
102 |
| -| line_size | lineSize | |
| 205 | + <!-- 控件水平内间距 --> |
| 206 | + <attr name="childPaddingHorizontal" format="dimension" /> |
| 207 | + <!-- 控件垂直内间距(可用于调整标题栏自适应的高度) --> |
| 208 | + <attr name="childPaddingVertical" format="dimension" /> |
103 | 209 |
|
104 |
| -* 极端适配:命名和之前完全不同 |
| 210 | + <!-- 中间标题 --> |
| 211 | + <attr name="title" format="string" /> |
| 212 | + <attr name="titleColor" format="color" /> |
| 213 | + <attr name="titleSize" format="dimension" /> |
| 214 | + <attr name="titleGravity"> |
| 215 | + <flag name="left" value="0x03" /> |
| 216 | + <flag name="right" value="0x05" /> |
| 217 | + <flag name="center" value="0x11" /> |
| 218 | + <flag name="start" value="0x00800003" /> |
| 219 | + <flag name="end" value="0x00800005" /> |
| 220 | + </attr> |
| 221 | + <attr name="titleStyle"> |
| 222 | + <flag name="normal" value="0" /> |
| 223 | + <flag name="bold" value="1" /> |
| 224 | + <flag name="italic" value="2" /> |
| 225 | + </attr> |
| 226 | + <attr name="titleIcon" format="reference" /> |
| 227 | + <attr name="titleIconWidth" format="dimension" /> |
| 228 | + <attr name="titleIconHeight" format="dimension" /> |
| 229 | + <attr name="titleIconPadding" format="dimension" /> |
| 230 | + <attr name="titleIconTint" format="color" /> |
| 231 | + <attr name="titleIconGravity"> |
| 232 | + <flag name="top" value="0x30" /> |
| 233 | + <flag name="bottom" value="0x50" /> |
| 234 | + <flag name="left" value="0x03" /> |
| 235 | + <flag name="right" value="0x05" /> |
| 236 | + <flag name="start" value="0x00800003" /> |
| 237 | + <flag name="end" value="0x00800005" /> |
| 238 | + </attr> |
105 | 239 |
|
106 |
| -| 3.5 版本 | 5.0 版本 | |
107 |
| -| :-------: | :-------: | |
108 |
| -| icon_back | backButton | |
| 240 | + <!-- 左边标题 --> |
| 241 | + <attr name="leftTitle" format="string"/> |
| 242 | + <attr name="leftTitleColor" format="color" /> |
| 243 | + <attr name="leftTitleSize" format="dimension" /> |
| 244 | + <attr name="leftTitleStyle"> |
| 245 | + <flag name="normal" value="0" /> |
| 246 | + <flag name="bold" value="1" /> |
| 247 | + <flag name="italic" value="2" /> |
| 248 | + </attr> |
| 249 | + <!-- leftIcon 优先于 backButton --> |
| 250 | + <attr name="leftIcon" format="reference" /> |
| 251 | + <attr name="leftIconWidth" format="dimension" /> |
| 252 | + <attr name="leftIconHeight" format="dimension" /> |
| 253 | + <attr name="leftIconPadding" format="dimension" /> |
| 254 | + <attr name="leftIconTint" format="color" /> |
| 255 | + <attr name="leftIconGravity"> |
| 256 | + <flag name="top" value="0x30" /> |
| 257 | + <flag name="bottom" value="0x50" /> |
| 258 | + <flag name="left" value="0x03" /> |
| 259 | + <flag name="right" value="0x05" /> |
| 260 | + <flag name="start" value="0x00800003" /> |
| 261 | + <flag name="end" value="0x00800005" /> |
| 262 | + </attr> |
| 263 | + <attr name="leftBackground" format="reference|color" /> |
| 264 | + |
| 265 | + <!-- 右边标题 --> |
| 266 | + <attr name="rightTitle" format="string" /> |
| 267 | + <attr name="rightTitleColor" format="color" /> |
| 268 | + <attr name="rightTitleSize" format="dimension" /> |
| 269 | + <attr name="rightTitleStyle"> |
| 270 | + <flag name="normal" value="0" /> |
| 271 | + <flag name="bold" value="1" /> |
| 272 | + <flag name="italic" value="2" /> |
| 273 | + </attr> |
| 274 | + <attr name="rightIcon" format="reference" /> |
| 275 | + <attr name="rightIconWidth" format="dimension" /> |
| 276 | + <attr name="rightIconHeight" format="dimension" /> |
| 277 | + <attr name="rightIconPadding" format="dimension" /> |
| 278 | + <attr name="rightIconTint" format="color" /> |
| 279 | + <attr name="rightIconGravity"> |
| 280 | + <flag name="top" value="0x30" /> |
| 281 | + <flag name="bottom" value="0x50" /> |
| 282 | + <flag name="left" value="0x03" /> |
| 283 | + <flag name="right" value="0x05" /> |
| 284 | + <flag name="start" value="0x00800003" /> |
| 285 | + <flag name="end" value="0x00800005" /> |
| 286 | + </attr> |
| 287 | + <attr name="rightBackground" format="reference|color" /> |
| 288 | + |
| 289 | + <!-- 分割线 --> |
| 290 | + <attr name="lineVisible" format="boolean" /> |
| 291 | + <attr name="lineDrawable" format="reference|color" /> |
| 292 | + <attr name="lineSize" format="dimension" /> |
| 293 | + |
| 294 | +</declare-styleable> |
| 295 | +``` |
109 | 296 |
|
110 |
| -* 无需适配:这个属性没有任何改动 |
111 | 297 |
|
112 |
| -| 3.5 版本 | 5.0 版本 | |
113 |
| -| :-----: | :-------: | |
114 |
| -| title | title | |
115 | 298 |
|
0 commit comments