https://github.com/wuhenzhizao/android-titlebar
🔥 通用,功能全面的自定义标题栏,支持沉浸式标题栏,颜色渐变,miui9
https://github.com/wuhenzhizao/android-titlebar
actionbar android title titlebar toolbar
Last synced: 14 days ago
JSON representation
🔥 通用,功能全面的自定义标题栏,支持沉浸式标题栏,颜色渐变,miui9
- Host: GitHub
- URL: https://github.com/wuhenzhizao/android-titlebar
- Owner: wuhenzhizao
- Created: 2017-08-29T06:15:21.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-07-10T05:24:35.000Z (almost 2 years ago)
- Last Synced: 2025-04-12T14:19:00.636Z (14 days ago)
- Topics: actionbar, android, title, titlebar, toolbar
- Language: Java
- Homepage:
- Size: 6.89 MB
- Stars: 962
- Watchers: 27
- Forks: 157
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CommonTitleBar
开发过程中,如果页面过多,需要构建大量重复的标题栏布局,浪费开发时间且不利于后期维护。本项目总结了几种常用的使用场景,将标题栏封装成控件,Java代码实现,对当前主流的沉浸式提供了支持,供有需要的同学使用,欢迎提供改进意见。
[Demo下载](https://fir.im/qj2a)
功能描述
=======
1. 支持左、中、右常规标题栏设置;
2. 支持自定义视图;
3. 支持沉浸式标题栏;|首页|快速预览|
|:---:|:---:|
||
|
|中间自定义+右边自定义|中间搜索框+左右自定义|
|:---:|:---:|
||
|
使用介绍
=======[ ](https://bintray.com/wuhenzhizao/maven/titlebar/_latestVersion)
添加依赖
```xml
buildscript {
allprojects {
repositories {
jcenter()
}
}
}dependencies {
compile 'com.wuhenzhizao:titlebar:1.2.0'
}
```布局中引入控件
```xml
// 中间自定义视图
```监听标题栏操作
===========
**点击事件**```java
titleBar.setListener(new CommonTitleBar.OnTitleBarListener() {
@Override
public void onClicked(View v, int action, String extra) {
if (action == CommonTitleBar.ACTION_LEFT_TEXT) {
...
}
// CommonTitleBar.ACTION_LEFT_TEXT; // 左边TextView被点击
// CommonTitleBar.ACTION_LEFT_BUTTON; // 左边ImageBtn被点击
// CommonTitleBar.ACTION_RIGHT_TEXT; // 右边TextView被点击
// CommonTitleBar.ACTION_RIGHT_BUTTON; // 右边ImageBtn被点击
// CommonTitleBar.ACTION_SEARCH; // 搜索框被点击,搜索框不可输入的状态下会被触发
// CommonTitleBar.ACTION_SEARCH_SUBMIT; // 搜索框输入状态下,键盘提交触发,此时,extra为输入内容
// CommonTitleBar.ACTION_SEARCH_VOICE; // 语音按钮被点击
// CommonTitleBar.ACTION_SEARCH_DELETE; // 搜索删除按钮被点击
// CommonTitleBar.ACTION_CENTER_TEXT; // 中间文字点击
}
});
```**双击事件**
```java
titleBar.setDoubleClickListener(new CommonTitleBar.OnTitleBarDoubleClickListener() {
@Override
public void onClicked(View v) {
Toast.makeText(MainActivity.this, "Titlebar double clicked!", Toast.LENGTH_SHORT).show();
}
});
```**自定义布局事件(以右侧自定义布局为例)**
```java
View rightCustomLayout = titleBar.getRightCustomView();
rightCustomLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {}
});
// 布局child view添加监听事件
rightCustomLayout.findViewById(R.id.子控件ID).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {}
});
```**动态切换状态栏图标颜色**
```java
titleBar.toggleStatusBarMode();
```注意点
=====
1. 如果出现全屏与键盘的冲突导致的键盘被遮挡问题,请在Activity.onAttachedToWindow()方法中加入如下代码,或在布局根节点加入 fitSystemWindow=true```java
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
KeyboardConflictCompat.assistWindow(getWindow());
}
```2. 若出现页面其他输入组件无法自动获取焦点的情况,请修改配置titlebar:centerTextMarquee="false"
更新日志
======* NEXT RELEASE
> 修复[#34](https://github.com/wuhenzhizao/android-titlebar/issues/34),导航栏适配问题;
> 增加跑马灯设置;
> 增加预览模式;* v1.2.0
> 修复[#51](https://github.com/wuhenzhizao/android-titlebar/issues/51),感谢@helloxkk;
> 编译环境升级,androidX兼容;* v1.1.4
> 增加对RTL的支持,感谢@coolBreezes;* v1.1.3
> 增加centerTextMarquee属性,灵活配置标题文字的跑马灯效果,解决标题栏开启跑马灯效果,页面其他输入框无法自动获取焦点的问题;* v1.1.2
> CommonTitleBar剥离KeyboardConflictCompat;* v1.1.0~1.1.1
> 重构StatusBarUtils,修复部分手机沉浸式标题栏失效的问题;最近的重心
========
[Kotlin-Adapter: 使用kotlin语法的BaseAdapter,语法简单,支持多种样式,支持多种效果,欢迎加star](https://github.com/wuhenzhizao/kotlin-adapter)技术交流
======
|QQ交流群|
|:---:|
||
License
=======
```
Copyright 2017 wuhenzhizaoLicensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```