本项目是基于开源项目TitleBar进行harmonyos化的移植和开发的,可以通过项目标签以及 github地址
移植版本:源master v9.2版本
一个标题栏框架。
不支持功能:
setLeftTint:设置左图色彩 --》 ohos暂不支持setColorFilter方法,无法实现该效果
setRightTint:设置右图色彩 --》 ohos暂不支持setColorFilter方法,无法实现该效果
demo未显示效果:
折叠效果未显示,此效果未demo中使用com.google.android.material.appbar.AppBarLayout
+ com.google.android.material.appbar.CollapsingToolbarLayout实现,ohos中无对应的组件,
同时该功能并非移植的组件的功能。
可以先下载项目,将项目中的library库提取出来放在所需项目中通过build配置
dependencies {
implementation project(":library")
}
buildscript {
repositories {
...
mavenCentral()
}
...
}
allprojects {
repositories {
...
mavenCentral()
}
}
dependencies {
implementation 'com.gitee.ts_ohos:titlebar:1.0.0'
}
<com.hjq.bar.TitleBar
ohos:id="$+id:tb_main_bar"
ohos:height="60vp"
ohos:width="match_parent"
ohos:top_margin="20vp"
ohos:padding="5vp"
app:leftIcon="$media:ic_launcher"
app:leftTitle="左边"
app:rightIcon="$media:ic_launcher"
app:rightTitle="右边"
app:title="监听标题栏点击事件"/>
监听点击事件: TitleBar titleBar = (TitleBar) findComponentById(ResourceTable.Id_tb_main_bar); titleBar.setOnTitleBarListener(new OnTitleBarListener() { @Override public void onLeftClick(Component view) { new ToastDialog(getContext()).setText("左项 View 被点击").show(); }
@Override
public void onTitleClick(Component view) {
new ToastDialog(getContext()).setText("中间 View 被点击").show();
}
@Override
public void onRightClick(Component view) {
new ToastDialog(getContext()).setText("右项 View 被点击").show();
}
});
你还可以为标题栏定义自己的样式,指定属性 barStyle:
<com.hjq.bar.TitleBar
ohos:height="50vp"
ohos:width="match_parent"
ohos:top_margin="20vp"
app:barStyle="night"
app:leftTitle="返回"
app:rightTitle="设置"
app:title="夜间模式的标题栏"/>
自定布局:
<com.hjq.bar.TitleBar
ohos:height="50vp"
ohos:width="match_content"
ohos:top_margin="20vp"
app:title="自定义标题栏">
<DirectionalLayout
ohos:height="match_content"
ohos:width="match_content"
ohos:alignment="end|vertical_center"
ohos:layout_alignment="end|vertical_center"
ohos:orientation="horizontal">
<Image
ohos:height="40vp"
ohos:width="40vp"
ohos:image_src="$media:ic_launcher"/>
<Image
ohos:height="40vp"
ohos:width="40vp"
ohos:end_margin="10vp"
ohos:image_src="$media:ic_launcher"
ohos:start_margin="5vp"/>
</DirectionalLayout>
</com.hjq.bar.TitleBar>
跑马灯效果:
<com.hjq.bar.TitleBar
ohos:height="50vp"
ohos:width="match_parent"
ohos:top_margin="20vp"
app:lineVisible="false"
app:pmdText="true"
app:title="标题开启跑马灯效果,就问你溜不溜"/>
Copyright 2018 Huang JinQun
Licensed 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 at
http://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.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。