Skip to content

Commit

Permalink
新增支持设置标题文本溢出处理模式
Browse files Browse the repository at this point in the history
修复标题栏中的 View 在某些情况下没有占满的问题
修复标题栏中的 View 在某些情况下大小会被压缩的问题
修复标题栏中的 View 在某些情况下显示的重心不对的问题
  • Loading branch information
getActivity committed Apr 1, 2023
1 parent 8e8e5a3 commit 93a999d
Show file tree
Hide file tree
Showing 24 changed files with 276 additions and 88 deletions.
4 changes: 3 additions & 1 deletion .github/ISSUE_TEMPLATE/issue_template_bug.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ assignees: getActivity

* 复现步骤【必填】:XXX(注意:目前不受理没有复现步骤的 Bug 单)

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

* 项目 targetSdkVersion【必填】:XX

* 出现问题的手机信息【必填】:请填写出现问题的品牌和机型

Expand Down
34 changes: 30 additions & 4 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/10.0/TitleBar.apk)
* 可以扫码下载 Demo 进行演示或者测试,如果扫码下载不了的,[点击此处可直接下载](https://github.com/getActivity/TitleBar/releases/download/10.2/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:10.0'
implementation 'com.github.getActivity:TitleBar:10.2'
}
```

#### 布局属性大全

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

<!-- 标题栏背景 -->
<attr name="android:background" />
Expand All @@ -74,7 +74,7 @@ dependencies {
<!-- 子控件垂直内间距(可用于调整标题栏自适应的高度) -->
<attr name="childVerticalPadding" format="dimension" />

<!-- 标题 -->
<!-- 中间标题 -->
<attr name="title" format="string" />
<attr name="titleColor" format="reference|color" />
<attr name="titleSize" format="dimension" />
Expand Down Expand Up @@ -104,6 +104,14 @@ dependencies {
<flag name="end" value="0x00800005" />
</attr>
<attr name="titleHorizontalPadding" format="dimension" />
<!-- 中间标题文本溢出处理模式(默认开启跑马灯) -->
<attr name="titleTextEllipsize">
<enum name="none" value="0" />
<enum name="start" value="1" />
<enum name="middle" value="2" />
<enum name="end" value="3" />
<enum name="marquee" value="4" />
</attr>

<!-- 左标题 -->
<attr name="leftTitle" format="string"/>
Expand All @@ -130,6 +138,14 @@ dependencies {
<attr name="leftBackground" format="reference|color" />
<attr name="leftForeground" format="reference|color" />
<attr name="leftHorizontalPadding" format="dimension" />
<!-- 左边标题文本溢出处理模式 -->
<attr name="leftTitleTextEllipsize">
<enum name="none" value="0" />
<enum name="start" value="1" />
<enum name="middle" value="2" />
<enum name="end" value="3" />
<enum name="marquee" value="4" />
</attr>

<!-- 右标题 -->
<attr name="rightTitle" format="string" />
Expand All @@ -156,6 +172,14 @@ dependencies {
<attr name="rightBackground" format="reference|color" />
<attr name="rightForeground" format="reference|color" />
<attr name="rightHorizontalPadding" format="dimension" />
<!-- 右边标题文本溢出处理模式 -->
<attr name="rightTitleTextEllipsize">
<enum name="none" value="0" />
<enum name="start" value="1" />
<enum name="middle" value="2" />
<enum name="end" value="3" />
<enum name="marquee" value="4" />
</attr>

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

* 表情包大集合:[EmojiPackage](https://github.com/getActivity/EmojiPackage) ![](https://img.shields.io/github/stars/getActivity/EmojiPackage.svg) ![](https://img.shields.io/github/forks/getActivity/EmojiPackage.svg)

* AI 资源大汇总:[AiIndex](https://github.com/getActivity/AiIndex) ![](https://img.shields.io/github/stars/getActivity/AiIndex.svg) ![](https://img.shields.io/github/forks/getActivity/AiIndex.svg)

* 省市区 Json 数据:[ProvinceJson](https://github.com/getActivity/ProvinceJson) ![](https://img.shields.io/github/stars/getActivity/ProvinceJson.svg) ![](https://img.shields.io/github/forks/getActivity/ProvinceJson.svg)

* Markdown 语法文档:[MarkdownDoc](https://github.com/getActivity/MarkdownDoc) ![](https://img.shields.io/github/stars/getActivity/MarkdownDoc.svg) ![](https://img.shields.io/github/forks/getActivity/MarkdownDoc.svg)
Expand Down
4 changes: 2 additions & 2 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 1000
versionName "10.0"
versionCode 1020
versionName "10.2"
}

// 支持 JDK 1.8
Expand Down
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
android:name=".AppApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

Expand Down
18 changes: 1 addition & 17 deletions app/src/main/java/com/hjq/bar/demo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* time : 2018/08/17
* desc : TitleBar 使用案例
*/
public final class MainActivity extends AppCompatActivity implements Runnable {
public final class MainActivity extends AppCompatActivity {

private static final Handler HANDLER = new Handler(Looper.getMainLooper());

Expand All @@ -43,21 +43,5 @@ public void onRightClick(TitleBar titleBar) {
Toaster.show("右项 View 被点击");
}
});

HANDLER.postDelayed(this, 2000);
}

@Override
public void run() {
TitleBar titleBar = findViewById(R.id.tb_main_bar_long_title);
titleBar.setLeftTitle("左边");
titleBar.setTitle("我是很长很长很长很长很长很长很长很长的标题");
titleBar.setRightTitle("右边");
}

@Override
protected void onDestroy() {
HANDLER.removeCallbacks(this);
super.onDestroy();
}
}
38 changes: 19 additions & 19 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@mipmap/title_bar_head"
android:src="@drawable/title_bar_head"
app:layout_collapseMode="parallax" />

<androidx.appcompat.widget.Toolbar
Expand Down Expand Up @@ -91,7 +91,7 @@
<com.hjq.bar.TitleBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="15dp"
app:leftIcon="@null"
app:title="不带返回按钮并标题斜体"
app:titleStyle="italic" />
Expand All @@ -109,14 +109,14 @@
<com.hjq.bar.TitleBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="15dp"
app:lineVisible="false"
app:title="不带分割线的标题栏" />

<com.hjq.bar.TitleBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="15dp"
app:leftHorizontalPadding="10dp"
app:lineVisible="false"
app:rightHorizontalPadding="10dp"
Expand All @@ -126,14 +126,14 @@
<com.hjq.bar.TitleBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="15dp"
app:childVerticalPadding="20dp"
app:title="通过垂直内间距来调整标题栏的高度" />

<com.hjq.bar.TitleBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="15dp"
app:leftIcon="@mipmap/ic_launcher"
app:leftIconHeight="20dp"
app:leftIconTint="#ff00ff"
Expand All @@ -153,7 +153,7 @@
<com.hjq.bar.TitleBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="15dp"
app:childVerticalPadding="8dp"
app:leftIcon="@drawable/qr_code_ic"
app:leftIconGravity="top"
Expand All @@ -179,7 +179,7 @@
<com.hjq.bar.TitleBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="15dp"
app:leftIcon="@null"
app:leftTitle="左边"
app:leftTitleColor="#FF3300"
Expand All @@ -195,7 +195,7 @@
android:id="@+id/tb_main_bar_click"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="15dp"
app:leftBackground="?attr/selectableItemBackground"
app:leftIcon="@mipmap/ic_launcher"
app:leftTitle="左边"
Expand All @@ -207,7 +207,7 @@
<com.hjq.bar.TitleBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="15dp"
app:barStyle="night"
app:leftTitle="返回"
app:rightTitle="设置"
Expand All @@ -216,7 +216,7 @@
<com.hjq.bar.TitleBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="15dp"
android:background="@drawable/shape_gradient"
app:barStyle="transparent"
app:leftTitle="返回"
Expand All @@ -226,7 +226,7 @@
<com.hjq.bar.TitleBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="15dp"
app:leftIcon="@null"
app:title="左边两个按钮效果" >

Expand Down Expand Up @@ -255,7 +255,7 @@
<com.hjq.bar.TitleBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="15dp"
app:leftIcon="@null"
app:title="右边两个按钮效果" >

Expand Down Expand Up @@ -285,7 +285,7 @@
<com.hjq.bar.TitleBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
android:layout_marginTop="15dp">

<LinearLayout
android:layout_width="wrap_content"
Expand Down Expand Up @@ -318,7 +318,7 @@
<com.hjq.bar.TitleBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="15dp"
app:leftIcon="@null"
app:leftTitle="我是很长很长很长很长很长的文案"
app:rightTitle="我是很长很长很长很长很长的文案"
Expand All @@ -328,11 +328,11 @@
android:id="@+id/tb_main_bar_long_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="15dp"
app:leftIcon="@null"
app:leftTitle="我是测试文案我是测试文案我是测试文案"
app:rightTitle="我是测试文案我是测试文案我是测试文案"
app:title="我是很长很长很长很长很长的标题" />
app:leftTitle="左边文案"
app:rightTitle="右边文案"
app:title="我是很长很长很长很长很长很长很长很长很长很长的标题" />

</LinearLayout>

Expand Down
Binary file removed app/src/main/res/mipmap-hdpi/ic_launcher.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-hdpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-mdpi/ic_launcher.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-mdpi/ic_launcher_round.png
Binary file not shown.
Binary file modified app/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
Binary file not shown.
Binary file modified app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
Binary file not shown.
Binary file added app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 1000
versionName "10.0"
versionCode 1020
versionName "10.2"
}

// 支持 JDK 1.8
Expand Down
16 changes: 16 additions & 0 deletions library/src/main/java/com/hjq/bar/ITitleBarStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.res.ColorStateList;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

Expand Down Expand Up @@ -238,6 +239,21 @@ public interface ITitleBarStyle {
*/
int getRightIconHeight(Context context);

/**
* 获取标题文本溢出的处理方式
*/
TextUtils.TruncateAt getTitleTextEllipsize(Context context);

/**
* 获取左标题文本溢出的处理方式
*/
TextUtils.TruncateAt getLeftTitleTextEllipsize(Context context);

/**
* 获取右标题文本溢出的处理方式
*/
TextUtils.TruncateAt getRightTitleTextEllipsize(Context context);

/**
* 分割线是否显示
*/
Expand Down
Loading

0 comments on commit 93a999d

Please sign in to comment.