当前位置: 首页 > news >正文

网站重构工程师/百度推广账户怎么开

网站重构工程师,百度推广账户怎么开,每日重大军事新闻,广告横幅在线制作之前已经写过一个在HarmonyOS中的自定义组件的案例,里面主要讲解了DrawTask这个接口的使用,从而让我们可以调用Canvas进行绘制。在之前的案例帖子中,有人回复问我如何实现自定义属性,现在这篇专门针对自定义属性写一篇帖子&#x…

之前已经写过一个在HarmonyOS中的自定义组件的案例,里面主要讲解了DrawTask这个接口的使用,从而让我们可以调用Canvas进行绘制。

在之前的案例帖子中,有人回复问我如何实现自定义属性,现在这篇专门针对自定义属性写一篇帖子,同时通过自定义属性自己封装了一个非常实用的标题栏TitleBar

不多说,首先上效果图

a70154d171372b6ffc8df3783680e871.png

这里主要真多标题栏的背景,标题文字、大小、颜色,左右两侧按钮是图标显示还是文字显示、是否显示分别进行了定制,后期用户使用只需要通过几个简单自定义属性的配置即可组合实现自己想要的效果。

具体实现思路如下,首先创建一个HarmonyOS Library模块mycustomtitlebar,在里面添加一个布局layout_titlebar.xml,代码如下<?xml  version="1.0" encoding="utf-8"?>

xmlns:ohos="http://schemas.huawei.com/res/ohos"

ohos:height="match_content"

ohos:width="match_parent">

ohos:id="$+id:title_bar_left"

ohos:height="match_content"

ohos:width="match_content"

ohos:align_parent_start="true"

ohos:left_padding="5vp"

ohos:min_height="45vp"

ohos:min_width="45vp"

ohos:text_size="14fp"

ohos:vertical_center="true"/>

ohos:id="$+id:titleText"

ohos:height="match_content"

ohos:width="match_content"

ohos:center_in_parent="true"

ohos:multiple_lines="false"

ohos:text_size="17fp"/>

ohos:id="$+id:title_bar_right"

ohos:height="match_content"

ohos:width="match_content"

ohos:align_parent_end="true"

ohos:left_padding="5vp"

ohos:min_height="45vp"

ohos:min_width="45vp"

ohos:right_margin="5vp"

ohos:text_size="14fp"

ohos:vertical_center="true"/>

然后创建一个自定义组件对应的类CustomTitleBar,代码如下:package com.xdw.mycustomtitlebar;

import ohos.agp.components.*;

import ohos.agp.utils.Color;

import ohos.app.Context;

import ohos.hiviewdfx.HiLog;

import ohos.hiviewdfx.HiLogLabel;

/**

* Created by 夏德旺 on 2021/3/4 10:01

*/

public class CustomTitleBar extends ComponentContainer {

private static final String TAG = "CustomTitleBar";

private static final HiLogLabel LABEL = new HiLogLabel(HiLog.DEBUG, 0, "TAG");

public CustomTitleBar(Context context) {

super(context);

}

public CustomTitleBar(Context context, AttrSet attrSet) {

super(context, attrSet);

//动态加载layout

Component component = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_layout_titlebar, null, false);

Button leftBtn = (Button) component.findComponentById(ResourceTable.Id_title_bar_left);

Text titleText = (Text) component.findComponentById(ResourceTable.Id_titleText);

Button rightBtn = (Button) component.findComponentById(ResourceTable.Id_title_bar_right);

//添加layout到父组件

addComponent(component);

//处理TitleBar背景色

if(attrSet.getAttr("bg_color").isPresent()){

component.setBackground(attrSet.getAttr("bg_color").get().getElement());

}else{

HiLog.error(LABEL,"attr bg_color is not present");

component.setBackground(getBackgroundElement());

}

//处理标题文字

if(attrSet.getAttr("title_text").isPresent()){

titleText.setText(attrSet.getAttr("title_text").get().getStringValue());

}else {

HiLog.error(LABEL,"attr title_text is not present");

titleText.setText("");

}

//处理标题大小

if(attrSet.getAttr("title_size").isPresent()){

titleText.setTextSize(attrSet.getAttr("title_size").get().getIntegerValue(), Text.TextSizeType.FP);

}else {

HiLog.error(LABEL,"attr title_size is not present");

}

//处理标题颜色

if(attrSet.getAttr("title_color").isPresent()){

titleText.setTextColor(attrSet.getAttr("title_color").get().getColorValue());

}else{

HiLog.error(LABEL,"attr title_color is not exist");

titleText.setTextColor(Color.BLACK);

}

//处理左边按钮

//获取是否要显示左边按钮

if(attrSet.getAttr("left_button_visible").isPresent()){

if(attrSet.getAttr("left_button_visible").get().getBoolValue()){

leftBtn.setVisibility(VISIBLE);

}else{

leftBtn.setVisibility(INVISIBLE);

}

}else{

//默认情况显示

HiLog.error(LABEL,"attr right_button_visible is not exist");

leftBtn.setVisibility(VISIBLE);

}

//处理左侧按钮的图标

if(attrSet.getAttr("left_button_icon").isPresent()){

leftBtn.setAroundElements(attrSet.getAttr("left_button_icon").get().getElement(),null,null,null);

}else{

HiLog.error(LABEL,"attr left_button_icon is not exist");

}

//处理左侧按钮的文本

if(attrSet.getAttr("left_button_text").isPresent()){

leftBtn.setText(attrSet.getAttr("left_button_text").get().getStringValue());

}else{

HiLog.error(LABEL,"attr left_button_text is not exist");

}

//处理左侧按钮的文本颜色

if(attrSet.getAttr("left_button_text_color").isPresent()){

leftBtn.setTextColor(attrSet.getAttr("left_button_text_color").get().getColorValue());

}else{

HiLog.error(LABEL,"attr left_button_text_color is not exist");

}

//处理左侧按钮的文本大小

if(attrSet.getAttr("left_button_text_size").isPresent()){

leftBtn.setTextSize(attrSet.getAttr("left_button_text_size").get().getIntegerValue(),Text.TextSizeType.FP);

}else{

HiLog.error(LABEL,"attr left_button_text_size is not exist");

}

//处理右边按钮

//获取是否要显示右边按钮

if(attrSet.getAttr("right_button_visible").isPresent()){

if(attrSet.getAttr("right_button_visible").get().getBoolValue()){

rightBtn.setVisibility(VISIBLE);

}else{

rightBtn.setVisibility(INVISIBLE);

}

}else{

//默认情况显示

HiLog.error(LABEL,"attr right_button_visible is not exist");

rightBtn.setVisibility(VISIBLE);

}

//处理右侧按钮的图标

if(attrSet.getAttr("right_button_icon").isPresent()){

rightBtn.setAroundElements(attrSet.getAttr("right_button_icon").get().getElement(),null,null,null);

}else{

HiLog.error(LABEL,"attr right_button_icon is not exist");

}

//处理右侧按钮的文本

if(attrSet.getAttr("right_button_text").isPresent()){

rightBtn.setText(attrSet.getAttr("right_button_text").get().getStringValue());

}else{

HiLog.error(LABEL,"attr right_button_text is not exist");

}

//处理右侧按钮的文本颜色

if(attrSet.getAttr("right_button_text_color").isPresent()){

rightBtn.setTextColor(attrSet.getAttr("right_button_text_color").get().getColorValue());

}else{

HiLog.error(LABEL,"attr right_button_text_color is not exist");

}

//处理右侧按钮的文本大小

if(attrSet.getAttr("right_button_text_size").isPresent()){

rightBtn.setTextSize(attrSet.getAttr("right_button_text_size").get().getIntegerValue(),Text.TextSizeType.FP);

}else{

HiLog.error(LABEL,"attr right_button_text_size is not exist");

}

}

public CustomTitleBar(Context context, AttrSet attrSet, String styleName) {

super(context, attrSet, styleName);

}

}

这里实现流程和Android中有点类似,但是有个很核心的区别就是没有Android中自定义属性所用到的一个attrs.xml文件中的declare-styleable功能。这里的自定义属性主要通过attrSet.getAttr代码来获取,获取的时候记得做下判断是否存在该属性,判断的api如下

attrSet.getAttr("bg_color").isPresent()

到此,该自定义组件就完成了,然后我们使用gradle将其打包成HAR包

e2ecc238cbee9fb5f20f6f34e052eb24.png

打包完成之后,会在output中生成一个har包,如下

文章后续内容和相关附件可以点击下面的原文链接前往学习

http://www.jmfq.cn/news/4772719.html

相关文章:

  • 网页设计模板素材图片旅游/太原seo代理商
  • 石家庄做外贸的网站建设/百度怎么推广自己的作品
  • 做美食下载什么网站/网站模板平台
  • 网页设计师个人简历参考范文/莱阳seo排名
  • 如何建一个个人网站/查网站域名
  • 网站上传可以通过/企业如何进行网站推广
  • 建设部网站官网挂证通报/千锋教育的官网
  • 住房与城乡建设部网站EPC/网站收录网
  • 响应式网站模板是什么/百度搜索关键词排名优化技术
  • 怀化北京网站建设/网络营销推广方案前言
  • 做外国订单有什么网站/网盘搜索引擎
  • 新手建网站视频教程/代发qq群发广告推广
  • 网站seo外包服务/微博推广方式有哪些
  • 百姓网app官方最新下载/网站优化包括哪些
  • 1网站免费建站/牛推网
  • wordpress 后台登录/优化设计英语
  • 公司网站设计案例/盐城seo排名
  • wordpress手机不能显示字体/朝阳区seo技术
  • 网上做网页网站任务赚钱/杭州做百度推广的公司
  • 一个服务器可以做几个网站/seo快速排名软件品牌
  • 小型旅游网站/网站推广系统方案
  • discuz 做企业网站/无锡网络公司
  • 建做一个av网站好/网站搭建的流程
  • wordpress 调用站外api/长尾词seo排名
  • 做口碑都有哪些网站/seo网络优化前景怎么样
  • 湖南长沙网站建设公司电话/大型seo公司
  • 的网站制作/如何提升网站seo排名
  • 做网页的it网站/怎么做推广网站
  • 孝感新闻门户网站/热点新闻事件素材
  • 用织梦做的学校网站/深圳设计公司