Skip to content

Commit

Permalink
新增标题栏支持设置左右的前景 Drawable 属性
Browse files Browse the repository at this point in the history
对 ChildHorizontalPadding 属性进行精细化拆分
修复在 Android 12 手机点击事件偶尔没有生效的问题
  • Loading branch information
getActivity committed Jun 25, 2022
1 parent 19e98ef commit 199dd17
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 122 deletions.
26 changes: 14 additions & 12 deletions .github/ISSUE_TEMPLATE/issue_template_bug.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,35 @@ assignees: getActivity

## 问题描述

* 框架版本:XXX
* 框架版本【必填】:XXX

* 问题描述:XXX
* 问题描述【必填】:XXX

* 复现步骤:XXX
* 复现步骤【必填】:XXX

* 是否必现:填是/否
* 是否必现【必填】:填是/否

* 手机信息:例如某米 9 / Android 10
* 出现问题的手机信息【必填】:请填写出现问题的品牌和机型

* 出现问题的安卓版本【必填】:请填写出现问题的 Android 版本

## 请回答

* 是部分机型还是所有机型都会出现:部分/全部(例如:某为,某 Android 版本会出现)
* 是部分机型还是所有机型都会出现【必答】:部分/全部(例如:某为,某 Android 版本会出现)

* 框架最新的版本是否存在这个问题:是/否(如果用的是旧版本的话,建议升级看问题是否还存在)
* 框架最新的版本是否存在这个问题【必答】:是/否(如果用的是旧版本的话,建议升级看问题是否还存在)

* 是否已经查阅框架文档还未能解决的:是/否(文档会提供最常见的问题解答,可以看看是否有自己想要的)
* 是否已经查阅框架文档还未能解决的【必答】:是/否(文档会提供最常见的问题解答,可以看看是否有自己想要的)

* issue 是否有人曾提过类似的问题:是/否(看看曾经有人提过类似的问题,先参考一下别人是怎么解决的)
* issue 是否有人曾提过类似的问题【必答】:是/否(看看曾经有人提过类似的问题,先参考一下别人是怎么解决的)

* 是否可以通过 Demo 来复现该问题:是/否(排查一下是不是自己的项目代码写得有问题导致的)
* 是否可以通过 Demo 来复现该问题【必答】:是/否(排查一下是不是自己的项目代码写得有问题导致的)

* 使用原生的 FrameLayout 来实现是否也会出现该问题:是/否(排查一下是不是框架的代码存在问题导致的)
* 使用原生的 FrameLayout 来实现是否也会出现该问题【非必答】:是/否(排查一下是不是框架的代码存在问题导致的)

## 其他

* 提供报错堆栈(如果有报错的话必填)
* 提供报错堆栈(如果有报错的话必填,注意不要拿被混淆过的代码堆栈上来

* 提供截图或视频(根据需要提供,此项不强制)

Expand Down
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/issue_template_suggest.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ assignees: getActivity

## 建议收集

* issue 是否有人曾提过类似的问题?(必答项,一旦出现重复提问我将不会再次解答)
* issue 是否有人曾提过类似的问题?【必答】(一旦出现重复提问我将不会再次解答)

* 你觉得框架有什么不足之处?(必答项,你可以描述框架有什么令你不满意的地方)
* 你觉得框架有什么不足之处?【必答】(你可以描述框架有什么令你不满意的地方)

* 你觉得该怎么去完善会比较好?(非必答项,你可以提供一下自己的想法或者做法供作者参考)
* 你觉得该怎么去完善会比较好?【非必答】(你可以提供一下自己的想法或者做法供作者参考)
14 changes: 14 additions & 0 deletions Adaptive.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

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

#### 从 9.3 以上的版本升级到 9.5 版本适配方案

* 修改 `app:childPaddingVertical` 属性名,请使用 `app:childVerticalPadding` 代替

* 拆分 `android:childPaddingHorizontal` 属性,将原有属性拆分为以下几个属性:

```text
app:titleHorizontalPadding
app:leftHorizontalPadding
app:rightHorizontalPadding
```

#### 从 5.0 以上的版本升级到 9.0 版本适配方案

* 删除 `app:backButton` 属性,请使用 `app:leftIcon` 代替,全局替换如下:
Expand Down
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

* 可以扫码下载 Demo 进行演示或者测试,如果扫码下载不了的,[点击此处可直接下载](https://github.com/getActivity/TitleBar/releases/download/9.3/TitleBar.apk)
* 可以扫码下载 Demo 进行演示或者测试,如果扫码下载不了的,[点击此处可直接下载](https://github.com/getActivity/TitleBar/releases/download/9.5/TitleBar.apk)

![](picture/demo_code.png)

Expand Down Expand Up @@ -51,14 +51,14 @@ android {
dependencies {
// 标题栏框架:https://github.com/getActivity/TitleBar
implementation 'com.github.getActivity:TitleBar:9.3'
implementation 'com.github.getActivity:TitleBar:9.5'
}
```

#### 布局属性大全

```xml
<declare-styleable name="TitleBar">
<declare-styleable name="TitleBar">

<!-- 标题栏背景 -->
<attr name="android:background" />
Expand All @@ -71,10 +71,8 @@ dependencies {
<enum name="ripple" value="0x40" />
</attr>

<!-- 子控件水平内间距 -->
<attr name="childPaddingHorizontal" format="dimension" />
<!-- 子控件垂直内间距(可用于调整标题栏自适应的高度) -->
<attr name="childPaddingVertical" format="dimension" />
<attr name="childVerticalPadding" format="dimension" />

<!-- 标题 -->
<attr name="title" format="string" />
Expand Down Expand Up @@ -105,6 +103,7 @@ dependencies {
<flag name="start" value="0x00800003" />
<flag name="end" value="0x00800005" />
</attr>
<attr name="titleHorizontalPadding" format="dimension" />

<!-- 左标题 -->
<attr name="leftTitle" format="string"/>
Expand All @@ -129,6 +128,8 @@ dependencies {
<flag name="end" value="0x00800005" />
</attr>
<attr name="leftBackground" format="reference|color" />
<attr name="leftForeground" format="reference|color" />
<attr name="leftHorizontalPadding" format="dimension" />

<!-- 右标题 -->
<attr name="rightTitle" format="string" />
Expand All @@ -153,6 +154,8 @@ dependencies {
<flag name="end" value="0x00800005" />
</attr>
<attr name="rightBackground" format="reference|color" />
<attr name="rightForeground" format="reference|color" />
<attr name="rightHorizontalPadding" format="dimension" />

<!-- 分割线 -->
<attr name="lineVisible" format="boolean" />
Expand Down Expand Up @@ -247,6 +250,8 @@ public class XxxApplication extends Application {

* Android 代码规范:[AndroidCodeStandard](https://github.com/getActivity/AndroidCodeStandard) ![](https://img.shields.io/github/stars/getActivity/AndroidCodeStandard.svg) ![](https://img.shields.io/github/forks/getActivity/AndroidCodeStandard.svg)

* Android 开源排行榜:[AndroidGithubBoss](https://github.com/getActivity/AndroidGithubBoss) ![](https://img.shields.io/github/stars/getActivity/AndroidGithubBoss.svg) ![](https://img.shields.io/github/forks/getActivity/AndroidGithubBoss.svg)

* Studio 精品插件:[StudioPlugins](https://github.com/getActivity/StudioPlugins) ![](https://img.shields.io/github/stars/getActivity/StudioPlugins.svg) ![](https://img.shields.io/github/forks/getActivity/StudioPlugins.svg)

* 表情包大集合:[EmojiPackage](https://github.com/getActivity/EmojiPackage) ![](https://img.shields.io/github/stars/getActivity/EmojiPackage.svg) ![](https://img.shields.io/github/forks/getActivity/EmojiPackage.svg)
Expand All @@ -257,7 +262,7 @@ public class XxxApplication extends Application {

![](https://raw.githubusercontent.com/getActivity/Donate/master/picture/official_ccount.png)

#### Android 技术分享 QQ 群:78797078
#### Android 技术 Q 群:10047167

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

Expand Down
14 changes: 8 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.hjq.bar.demo"
minSdkVersion 17
targetSdkVersion 31
versionCode 93
versionName "9.3"
versionCode 95
versionName "9.5"
}

// 支持 JDK 1.8
Expand Down Expand Up @@ -50,17 +50,19 @@ android {
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
// 依赖 libs 目录下所有的 jar 和 aar 包
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')

implementation project(':library')

// AndroidX 库:https://github.com/androidx/androidx
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.appcompat:appcompat:1.4.0'
// Material 库:https://github.com/material-components/material-components-android
implementation 'com.google.android.material:material:1.4.0'

// 吐司工具类:https://github.com/getActivity/ToastUtils
implementation 'com.github.getActivity:ToastUtils:10.0'
implementation 'com.github.getActivity:ToastUtils:10.3'

// 内存泄漏捕捉:https://github.com/square/leakcanary
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1'
}
23 changes: 14 additions & 9 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:childPaddingHorizontal="25dp"
app:childPaddingVertical="15dp"
app:childVerticalPadding="15dp"
app:leftIcon="@null"
app:title="标题向左对齐并且加粗"
app:titleGravity="start"
Expand All @@ -118,14 +117,17 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:leftHorizontalPadding="10dp"
app:lineVisible="false"
app:title="标题文字过多会自动开启自带跑马灯效果,就问你溜不溜" />
app:rightHorizontalPadding="10dp"
app:title="标题文字过多会自动开启自带跑马灯效果,就问你溜不溜"
app:titleHorizontalPadding="0dp" />

<com.hjq.bar.TitleBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:childPaddingVertical="20dp"
app:childVerticalPadding="20dp"
app:title="通过垂直内间距来调整标题栏的高度" />

<com.hjq.bar.TitleBar
Expand All @@ -152,7 +154,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:childPaddingVertical="8dp"
app:childVerticalPadding="8dp"
app:leftIcon="@drawable/qr_code_ic"
app:leftIconGravity="top"
app:leftIconHeight="20dp"
Expand Down Expand Up @@ -194,8 +196,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:leftBackground="?attr/selectableItemBackground"
app:leftIcon="@mipmap/ic_launcher"
app:leftTitle="左边"
app:rightBackground="?attr/selectableItemBackground"
app:rightIcon="@mipmap/ic_launcher"
app:rightTitle="右边"
app:title="监听标题栏点击事件" />
Expand Down Expand Up @@ -261,10 +265,11 @@
android:layout_gravity="end|center_vertical"
android:orientation="horizontal" >

<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@mipmap/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="我是文本" />

<ImageView
android:layout_width="40dp"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">TitleBar</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<!-- Base application theme. -->
Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ android {

defaultConfig {
minSdkVersion 16
versionCode 93
versionName "9.3"
versionCode 95
versionName "9.5"
}

// 支持 JDK 1.8
Expand Down
24 changes: 22 additions & 2 deletions library/src/main/java/com/hjq/bar/ITitleBarStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,35 @@ public interface ITitleBarStyle {
*/
Drawable getRightTitleBackground(Context context);

/**
* 获取左标题的按钮前景
*/
Drawable getLeftTitleForeground(Context context);

/**
* 获取右标题的按钮前景
*/
Drawable getRightTitleForeground(Context context);

/**
* 获取默认按钮图片
*/
Drawable getBackButtonDrawable(Context context);

/**
* 获取子控件的水平内间距
* 获取左标题子控件的水平内间距
*/
int getLeftHorizontalPadding(Context context);

/**
* 获取标题子控件的水平内间距
*/
int getTitleHorizontalPadding(Context context);

/**
* 获取右标题子控件的水平内间距
*/
int getChildHorizontalPadding(Context context);
int getRightHorizontalPadding(Context context);

/**
* 获取子控件的垂直内间距
Expand Down
Loading

0 comments on commit 199dd17

Please sign in to comment.