Multi-functional, universal, can be implemented in the layout or using Java code to achieve the title bar; support the left back button (no need to manually implement page return), the left side supports pictures + text, pictures, text; the right side Support pictures, text, etc.
This library has been inspired by SiberiaDante/TitleLayout
From Source
- For using TitleLayout module in sample app, include the source code and add the below dependencies in entry/build.gradle to generate hap/support.har.
implementation project(path: ':titlelayout')
- For using TitleLayout module in separate application using har file, add the har file in the entry/libs folder and add the dependencies in entry/build.gradle file.
implementation fileTree(dir: 'libs', include: ['*.har'])
<com.siberiadante.titlelayoutlib.TitleBarLayout
ohos:id="$+id:title_layout_one"
ohos:layout_width="match_parent"
ohos:layout_height="match_content"
dante:d_is_back_view="true"
dante:d_left_image="$media:back_gray"
dante:d_left_image_padding_start="10vp"
dante:d_left_image_width="30vp"
dante:d_left_text="back"
dante:d_left_text_style="normal"
dante:d_left_text_color="$color:black"
dante:d_left_text_padding_start="10vp"
dante:d_left_text_size="45fp"
dante:d_line_height="1px"
dante:d_right_text="submit"
dante:d_right_text_size="45fp"
dante:d_right_text_style="normal"
dante:d_right_text_color="$color:white"
dante:d_title_size="50vp"
dante:d_title_style="bold"
dante:d_title_text="Here is title"
dante:d_title_color="$color:black"
dante:d_subtitle_size="11fp"
dante:d_subtitle_style="normal"
dante:d_subtitle_text="subtitle"
dante:d_subtitle_color="$color:gray"
dante:d_title_layout_background="$color:red"
dante:d_title_layout_height="70vp"/>
final TitleBarLayout titleBarLayout = (TitleBarLayout) findComponentById(ResourceTable.Id_title_layout_one);
titleBarLayout.setIsLeftBackView(true);
titleBarLayout.setTitleLayoutBackground(Color.BLUE);
titleBarLayout.setRightImageClickListener(new Component.ClickedListener() {
@Override
public void onClick(Component view) {
new ToastDialog(MainAbility.this).setText("The picture on the right was clicked").show();
}
});
titleBarLayout.setTitleClickListener(new OnMultiTouchListener(new TitleLayoutListener() {
@Override
public void onTitleClickListener() {
new ToastDialog(MainAbility.this).setText("Title was clicked").show();
}
@Override
public void onTitleDoubleClickListener() {
new ToastDialog(MainAbility.this).setText("Title was double clicked").show();
}
}));
-
If the left text or button is the return key, just use the following code in the layout:
dante:d_is_back_view="true"
-
Or in Java code:
titleLayout.setIsLeftBackView(true)
-
There is no need to set onClickListener, this.finish, etc.; if you have special needs, you can set the attribute to false to implement the method:
setLeftClickListener(OnClickListener listener)
xml Attributes | Property description |
d_left_image | Left image resources |
d_left_image_width | Left picture widte (high to match the father layout) |
d_left_image_padding_start | Left picture left margins |
d_left_image_padding_end | Left picture right margins |
d_left_text | Left text resources |
d_left_text_size | Left text size |
d_left_text_color | Left text color (default black) |
d_left_text_style | Set text style (Normal | Bold) |
d_left_text_padding_start | Left word left margins |
d_left_text_padding_end | Left word right margins |
d_title_text | Intermediate header text resources |
d_title_size | Intermediate title text size |
d_title_color | Intermediate header text color (default black) |
d_title_style | Set text style (normal | bold) |
d_subtitle_text | Intermediate subtitle text resources |
d_subtitle_size | Intermediate subtitle text size |
d_subtitle_color | Intermediate subtitle text color (default black) |
d_subtitle_style | Set text style (normal | bold) |
d_right_text | Right text resources |
d_right_text_color | Right text color |
d_right_text_size | Right text size |
d_right_text_style | Set text style (bormal | bold) |
d_right_text_padding_end | Right text distance from the right |
d_right_text_padding_start | Right text distance from the left |
d_right_image | Right image resources |
d_right_image_width | Width of the right image |
d_right_image_padding_end | Right image distance from the right |
d_right_image_padding_start | Right image distance from the left |
d_line_height | The bottom horizontal line height of the title column (recommended units using PX) |
d_line_background | Title bar bottom horizontal line background color (default black) |
d_title_layout_height | Title bar overall height |
d_title_layout_background | Title bar overall background color |
d_is_back_view | Whether the left text and the image is a return button, if it is returned, come back to the previous page function |
Java code method | Java code method description |
setTitle(CharSequence title) | Set the title resource |
setTitleSize(int titleSize) | Set the title font size |
setTitleColor(int titleColor) | Set the title font color |
setTitleStyle(String title, int titleSize, int titleColor) | Set the title resource, text size, text color |
setSubTitle(CharSequence title) | Set the subtitle resource |
setSubTitleSize(int titleSize) | Set the subtitle font size |
setSubTitleColor(int titleColor) | Set the subtitle font color |
setSubTitleStyle(String title, int titleSize, int titleColor) | Set the subtitle resource, text size, text color |
setLeftText(String leftText) | Set the left text |
setLeftTextSize(int leftTextSize) | Set the size of the word left |
setLeftTextColor(int leftTextColor) | Set the left text color |
setLeftStyle(String leftText, int leftTextSize, int leftTextColor) | Set the left text, text size, text color |
setRightText(String rightText) | Set the right text |
setRightTextSize(int rightTextSize) | Set the right text size |
setRightTextColor(int rightTextColor) | Set the right text color |
setLeftImage(int imageResId) | Set the left image |
setRightImage(int imageResId) | Set the right image |
setTitleClickListener(OnClickListener listener) | Title Click to listen |
setTitleClickListener(OnMultiTouchListener listener) | Set the title Click / Double-click Event |
setLeftClickListener(OnClickListener listener) | On the left and buttons, click on the monitor |
setRightTextClickListener(OnClickListener listener) | Right side text Click to listen |
setRightImageClickListener(OnClickListener listener) | Right button Click to listen |
setIsLeftBackView(boolean isLeftBackView) | Set whether the left text and buttons are returned button |
setIsHaveLine(boolean haveLine) | Set whether there is a split line at the bottom of the title bar |
setLeftBackViewVisible | Set the left icon to display or hidden |
setLeftTextViewVisible | Set the left text display or hidden |
setRightTextViewVisible | Set the right side display or hidden |
setRightImageViewVisible | Set the right icon to display or hidden |
setTitleVisible | Set the title display or hidden |
setSubTitleVisible | Set the subtitle display or hidden |
setTitleLayoutBackground | Set the title bar background color |
TitleLayout is released under the Apache License Version 2.0.