Skip to content

Commit e09cebc

Browse files
committed
优化代码命名
修正内间距的逻辑
1 parent e507265 commit e09cebc

22 files changed

+223
-188
lines changed

.gitignore

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
*.iml
2-
.gradle
3-
/local.properties
4-
/.idea/workspace.xml
5-
/.idea/libraries
6-
.DS_Store
1+
/.gradle
2+
/.idea
73
/build
4+
*/build
85
/captures
9-
/.idea
6+
/.cxx
7+
*/.cxx
8+
/.externalNativeBuild
109

11-
/app/*.pro
12-
13-
/library/*.pro
10+
._*
11+
*.iml
12+
.DS_Store
13+
local.properties

Adaptive.md

Lines changed: 97 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,115 @@
1-
# 关于适配的问题
1+
# 关于属性适配的问题
22

3-
> 你好,如果你是刚使用这个库的人不必理会,如果你之前使用了 `TitleBar` 这个库,也就是 5.0 版本以下的,在升级到 `5.0` 版本后需要进行适配,否则 `Android Studio` 会报错`编译不通过`,对于这个问题我表示十分抱歉,低版本的 `xml` 属性命名得并不是很规范,现在在 `5.0` 版本给予了纠正,尽管这次的代价比较大,但是我会义无反顾去做,如果你使用了 `TitleBar` 但是不想进行适配,请不要`升级`依赖版本
3+
* 你好,如果你是刚使用这个库的人可以不必理会,如果你之前使用了 `TitleBar` 这个库,也就是 5.0 版本以下的,在升级到 `5.0` 版本后需要进行适配,否则 `Android Studio` 会报错`编译不通过`,对于这个问题我表示十分抱歉,低版本的 `xml` 属性命名得并不是很规范,现在在 `5.0` 版本给予了纠正,尽管这次的代价比较大,但是我会义无反顾去做,如果你使用了 `TitleBar` 但是不想进行适配,请不要`升级`依赖版本
44

55
#### 3.5 版本属性命名
66

7-
<declare-styleable name="TitleBar">
8-
<!-- 标题栏的样式 -->
9-
<attr name="bar_style">
10-
<enum name="light" value="0x10" />
11-
<enum name="night" value="0x20" />
12-
<enum name="transparent" value="0x30" />
13-
</attr>
14-
<!-- 标题 -->
15-
<attr name="title" format="string" />
16-
<attr name="title_left" format="string"/>
17-
<attr name="title_right" format="string" />
18-
<!-- 图标 -->
19-
<attr name="icon_left" format="reference" />
20-
<attr name="icon_right" format="reference" />
21-
<!-- 返回按钮,默认开 -->
22-
<attr name="icon_back" format="boolean" />
23-
<!-- 文字颜色 -->
24-
<attr name="color_title" format="color" />
25-
<attr name="color_right" format="color" />
26-
<attr name="color_left" format="color" />
27-
<!-- 文字大小 -->
28-
<attr name="size_title" format="dimension" />
29-
<attr name="size_right" format="dimension" />
30-
<attr name="size_left" format="dimension" />
31-
<!-- 按钮背景 -->
32-
<attr name="background_left" format="reference|color" />
33-
<attr name="background_right" format="reference|color" />
34-
<!-- 分割线 -->
35-
<attr name="line_visible" format="boolean" />
36-
<attr name="line_color" format="color" />
37-
<attr name="line_size" format="dimension" />
38-
</declare-styleable>
7+
```xml
8+
<declare-styleable name="TitleBar">
9+
<!-- 标题栏的样式 -->
10+
<attr name="bar_style">
11+
<enum name="light" value="0x10" />
12+
<enum name="night" value="0x20" />
13+
<enum name="transparent" value="0x30" />
14+
</attr>
15+
<!-- 标题 -->
16+
<attr name="title" format="string" />
17+
<attr name="title_left" format="string"/>
18+
<attr name="title_right" format="string" />
19+
<!-- 图标 -->
20+
<attr name="icon_left" format="reference" />
21+
<attr name="icon_right" format="reference" />
22+
<!-- 返回按钮,默认开 -->
23+
<attr name="icon_back" format="boolean" />
24+
<!-- 文字颜色 -->
25+
<attr name="color_title" format="color" />
26+
<attr name="color_right" format="color" />
27+
<attr name="color_left" format="color" />
28+
<!-- 文字大小 -->
29+
<attr name="size_title" format="dimension" />
30+
<attr name="size_right" format="dimension" />
31+
<attr name="size_left" format="dimension" />
32+
<!-- 按钮背景 -->
33+
<attr name="background_left" format="reference|color" />
34+
<attr name="background_right" format="reference|color" />
35+
<!-- 分割线 -->
36+
<attr name="line_visible" format="boolean" />
37+
<attr name="line_color" format="color" />
38+
<attr name="line_size" format="dimension" />
39+
</declare-styleable>
40+
```
3941

4042
#### 5.0 版本属性命名
4143

42-
<declare-styleable name="TitleBar" tools:ignore="ResourceName">
43-
<!-- 整体样式 -->
44-
<attr name="barStyle">
45-
<enum name="light" value="0x10" />
46-
<enum name="night" value="0x20" />
47-
<enum name="transparent" value="0x30" />
48-
</attr>
49-
<!-- 中间 -->
50-
<attr name="title" format="string" />
51-
<attr name="titleColor" format="color" />
52-
<attr name="titleSize" format="dimension" />
53-
<!-- 左边 -->
54-
<attr name="leftTitle" format="string"/>
55-
<attr name="leftIcon" format="reference" /><!-- leftIcon 优先于 backButton -->
56-
<attr name="backButton" format="boolean" /><!-- 返回按钮(默认开) -->
57-
<attr name="leftColor" format="color" />
58-
<attr name="leftSize" format="dimension" />
59-
<attr name="leftBackground" format="reference|color" />
60-
<!-- 右边 -->
61-
<attr name="rightTitle" format="string" />
62-
<attr name="rightIcon" format="reference" />
63-
<attr name="rightColor" format="color" />
64-
<attr name="rightSize" format="dimension" />
65-
<attr name="rightBackground" format="reference|color" />
66-
<!-- 分割线 -->
67-
<attr name="lineVisible" format="boolean" />
68-
<attr name="lineColor" format="reference|color" />
69-
<attr name="lineSize" format="dimension" />
70-
</declare-styleable>
44+
```xml
45+
<declare-styleable name="TitleBar" tools:ignore="ResourceName">
46+
<!-- 整体样式 -->
47+
<attr name="barStyle">
48+
<enum name="light" value="0x10" />
49+
<enum name="night" value="0x20" />
50+
<enum name="transparent" value="0x30" />
51+
</attr>
52+
<!-- 中间 -->
53+
<attr name="title" format="string" />
54+
<attr name="titleColor" format="color" />
55+
<attr name="titleSize" format="dimension" />
56+
<!-- 左边 -->
57+
<attr name="leftTitle" format="string"/>
58+
<attr name="leftIcon" format="reference" /><!-- leftIcon 优先于 backButton -->
59+
<attr name="backButton" format="boolean" /><!-- 返回按钮(默认开) -->
60+
<attr name="leftColor" format="color" />
61+
<attr name="leftSize" format="dimension" />
62+
<attr name="leftBackground" format="reference|color" />
63+
<!-- 右边 -->
64+
<attr name="rightTitle" format="string" />
65+
<attr name="rightIcon" format="reference" />
66+
<attr name="rightColor" format="color" />
67+
<attr name="rightSize" format="dimension" />
68+
<attr name="rightBackground" format="reference|color" />
69+
<!-- 分割线 -->
70+
<attr name="lineVisible" format="boolean" />
71+
<attr name="lineColor" format="reference|color" />
72+
<attr name="lineSize" format="dimension" />
73+
</declare-styleable>
74+
```
7175

7276
#### 适配方案
7377

74-
> 常规适配:单词反向,不再采用下划线形式,而用单词开头大写的方式代替
78+
* 常规适配:单词反向,不再采用下划线形式,而用单词开头大写的方式代替
7579

76-
3.5 版本 | 5.0 版本
77-
------------ | -------------
78-
title_left | leftTitle
79-
title_right | rightTitle
80-
icon_left | leftIcon
81-
icon_right | rightIcon
82-
color_title | titleColor
83-
color_right | rightColor
84-
color_left | leftColor
85-
size_title | titleSize
86-
size_right | rightSize
87-
size_left | leftSize
88-
background_left | leftBackground
89-
background_right| rightBackground
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 |
9094

91-
> 特殊适配:去除下划线,并且用单词开头大写的方式代替
95+
* 特殊适配:去除下划线,并且用单词开头大写的方式代替
9296

93-
3.5 版本 | 5.0 版本
94-
------- | -------------
95-
bar_style | barStyle
96-
line_visible | lineVisible
97-
line_color | lineColor
98-
line_size | lineSize
97+
| 3.5 版本 | 5.0 版本 |
98+
| :-------: | :---------: |
99+
| bar_style | barStyle |
100+
| line_visible | lineVisible |
101+
| line_color | lineColor |
102+
| line_size | lineSize |
99103

100-
> 极端适配:命名和之前完全不同
104+
* 极端适配:命名和之前完全不同
101105

102-
3.5 版本 | 5.0 版本
103-
------- | -------------
104-
icon_back | backButton
106+
| 3.5 版本 | 5.0 版本 |
107+
| :-------: | :-------: |
108+
| icon_back | backButton |
105109

106-
> 无需适配:这个属性没有任何改动
110+
* 无需适配:这个属性没有任何改动
107111

108-
3.5 版本 | 5.0 版本
109-
------ | -------------
110-
title | title
112+
| 3.5 版本 | 5.0 版本 |
113+
| :-----: | :-------: |
114+
| title | title |
111115

README.md

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# 标题栏
1+
# 标题栏框架
22

3-
> 码云地址:[Gitee](https://gitee.com/getActivity/TitleBar)
3+
* 码云地址:[Gitee](https://gitee.com/getActivity/TitleBar)
44

5-
> 博客地址:[Android标题栏(TitleBar)绝佳解决方案](https://www.jianshu.com/p/617be02dc265)
5+
* 博客地址:[Android标题栏(TitleBar)绝佳解决方案](https://www.jianshu.com/p/617be02dc265)
66

7-
> 已投入公司项目多时,没有任何毛病,可胜任任何需求,[点击此处下载Demo](TitleBar.apk)
7+
* 已投入公司项目多时,没有任何毛病,可胜任任何需求,[点击此处下载Demo](TitleBar.apk)
88

9-
> 想了解实现原理的可以参考文章:[纯手工打造一个通用的标题栏 TitleBar](https://www.jianshu.com/p/ccf6506335e7)
9+
* 想了解实现原理的可以参考文章:[纯手工打造一个通用的标题栏 TitleBar](https://www.jianshu.com/p/ccf6506335e7)
1010

1111
![](TitleBar.gif)
1212

@@ -17,7 +17,7 @@
1717
```groovy
1818
dependencies {
1919
// 标题栏框架:https://github.com/getActivity/TitleBar
20-
implementation 'com.hjq:titlebar:8.2'
20+
implementation 'com.hjq:titlebar:8.5'
2121
}
2222
```
2323

@@ -37,12 +37,8 @@ dependencies {
3737
<attr name="titleColor" format="color" />
3838
<attr name="titleSize" format="dimension" />
3939
<attr name="titleGravity">
40-
<flag name="top" value="0x30" />
41-
<flag name="bottom" value="0x50" />
4240
<flag name="left" value="0x03" />
4341
<flag name="right" value="0x05" />
44-
<flag name="center_vertical" value="0x10" />
45-
<flag name="center_horizontal" value="0x01" />
4642
<flag name="center" value="0x11" />
4743
<flag name="start" value="0x00800003" />
4844
<flag name="end" value="0x00800005" />
@@ -101,17 +97,17 @@ dependencies {
10197
mTitleBar.setOnTitleBarListener(new OnTitleBarListener() {
10298

10399
@Override
104-
public void onLeftClick(View v) {
100+
public void onLeftClick(View view) {
105101
ToastUtils.show("左项View被点击");
106102
}
107103

108104
@Override
109-
public void onTitleClick(View v) {
105+
public void onTitleClick(View view) {
110106
ToastUtils.show("中间View被点击");
111107
}
112108

113109
@Override
114-
public void onRightClick(View v) {
110+
public void onRightClick(View view) {
115111
ToastUtils.show("右项View被点击");
116112
}
117113
});
@@ -130,6 +126,12 @@ public class XXApplication extends Application {
130126

131127
// 初始化 TitleBar
132128
TitleBar.setDefaultInitializer(new LightBarInitializer() {
129+
130+
@Override
131+
protected TextView createTextView(Context context) {
132+
return new AppCompatTextView(context);
133+
}
134+
133135
@Override
134136
public TextView getLeftView(Context context) {
135137
return super.getLeftView(context);
@@ -194,8 +196,6 @@ public class XXApplication extends Application {
194196

195197
* 网络框架:[EasyHttp](https://github.com/getActivity/EasyHttp)
196198

197-
* 日志框架:[Logcat](https://github.com/getActivity/Logcat)
198-
199199
* 权限框架:[XXPermissions](https://github.com/getActivity/XXPermissions)
200200

201201
* 吐司框架:[ToastUtils](https://github.com/getActivity/ToastUtils)
@@ -204,7 +204,15 @@ public class XXApplication extends Application {
204204

205205
* 悬浮窗框架:[XToast](https://github.com/getActivity/XToast)
206206

207-
#### Android技术讨论Q群:78797078
207+
* Gson 解析容错:[GsonFactory](https://github.com/getActivity/GsonFactory)
208+
209+
* 日志查看框架:[Logcat](https://github.com/getActivity/Logcat)
210+
211+
#### 微信公众号:Android轮子哥
212+
213+
![](https://raw.githubusercontent.com/getActivity/Donate/master/picture/official_ccount.png)
214+
215+
#### Android 技术分享 QQ 群:78797078
208216

209217
#### 如果您觉得我的开源库帮你节省了大量的开发时间,请扫描下方的二维码随意打赏,要是能打赏个 10.24 :monkey_face:就太:thumbsup:了。您的支持将鼓励我继续创作:octocat:
210218

TitleBar.apk

121 KB
Binary file not shown.

app/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId "com.hjq.bar.demo"
88
minSdkVersion 16
99
targetSdkVersion 28
10-
versionCode 82
11-
versionName "8.2"
10+
versionCode 85
11+
versionName "8.5"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1313
}
1414
buildTypes {

app/proguard-rules.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-keep class com.hjq.bar.** {*;}

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
package="com.hjq.bar.demo">
44

55
<application
6-
android:name=".MainApplication"
6+
android:name=".AppApplication"
77
android:icon="@mipmap/ic_launcher"
88
android:label="@string/app_name"
99
android:roundIcon="@mipmap/ic_launcher_round"

app/src/main/java/com/hjq/bar/demo/MainApplication.java renamed to app/src/main/java/com/hjq/bar/demo/AppApplication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import com.hjq.bar.initializer.LightBarInitializer;
1010
import com.hjq.toast.ToastUtils;
1111

12-
public class MainApplication extends Application {
12+
public final class AppApplication extends Application {
1313

1414
@Override
1515
public void onCreate() {
@@ -26,4 +26,4 @@ protected TextView createTextView(Context context) {
2626
}
2727
});
2828
}
29-
}
29+
}

0 commit comments

Comments
 (0)