TitleLayout

Versatile, general purpose, title bar can be implemented in layout or using Java code; Support immersive status bar, support the left back button (no need to manually achieve page return), the left support picture + text, picture, text; The right side supports images and text.

Welcome to:

Lot – https://github.com/SiberiaDante/TitleLayout

Gradle depends on:

   compile 'com. Making. SiberiaDante: TitleLayout: v1.1.0'
Copy the code

The picture is a little bit empty

Use:

<com.siberiadante.titlelayoutlib.TitleBarLayout
        android:id="@+id/title_layout_one"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        dante:d_is_back_view="true"
        dante:d_is_immersive_state_bar="true"
        dante:d_left_image="@mipmap/back_gray"
        dante:d_left_image_padding_start="10dp"
        dante:d_left_image_width="30dp"
        dante:d_left_text="Test"
        dante:d_left_text_style="normal"
        dante:d_left_text_color="@color/black"
        dante:d_left_text_padding_start="10dp"
        dante:d_left_text_size="14sp"
        dante:d_line_height="1px"
        dante:d_right_text="Report"
        dante:d_right_text_size="14sp"
        dante:d_right_text_style="normal"
        dante:d_right_text_color="@color/white"
        dante:d_title_size="18sp"
        dante:d_title_style="mormal"
        dante:d_title_text="Here's the title."
        dante:d_title_color="@color/black"
        dante:d_subtitle_size="11sp"
        dante:d_subtitle_style="mormal"
        dante:d_subtitle_text="Here's the subtitle."
        dante:d_subtitle_color="@color/gray"
        dante:d_title_layout_background="@color/red"
        dante:d_title_layout_height="45dp"/>
Copy the code

Using Java code:

  TitleBarLayout titleBarLayout = (TitleBarLayout) findViewById(R.id.title_layout);
        titleBarLayout.setTitleClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                LogUtil.d("Title was clicked."); }}); / / set Titlesize titleBarLayout. SetTitleSize (30); . / / a key setting heading styles titleBarLayout setTitleStyle ("I am the title.", 18, ContextCompat.getColor(this, R.color.action_sheet_blue));
        titleBarLayout.setRightImageClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                LogUtil.d("The picture on the right is clicked."); }});Copy the code

Key notes:

  • If the text or button on the left is a return key, just use the following code in the layout:
    dante:d_is_back_view="true"
    Copy the code

    Or in Java code

    titleLayout.setIsLeftBackView(true)
    Copy the code

    No need to set onClickListener, this.finish, etc. If you have special requirements, you can set the property to false.

    setLeftClickListener(OnClickListener listener)
    Copy the code
  • If an immersive status bar is used in a project, it needs to be in the layout
    dante:d_is_immersive_state_bar="true"
    Copy the code
  • Setting the page as an immersive status bar method:
     ScreenUtil.setStatusTranslucent(this);
    Copy the code

Other Attributes

Attributes in XML:

XML attributes Attributes that
d_left_image Left image resources
d_left_image_width Left image width (height matches parent layout)
d_left_image_padding_start Left margin of left image (default 10dp)
d_left_text Left text resources
d_left_text_size Left text size (default 16SP)
d_left_text_color Left text color (black by default)
d_left_text_style Set the text style (normal | bold | italic)
d_left_text_padding_start Left margin of left text (default 10dp)
d_title_text Middle title text resources
d_title_size Middle heading text size (default 18SP)
d_title_color Middle heading text color (black by default)
d_title_style Set the text style (normal | bold | italic)
d_subtitle_text Middle subtitle text resources
d_subtitle_size Middle subheading text size (default 12SP)
d_subtitle_color Middle subtitle text color (black by default)
d_subtitle_style Set the text style (normal | bold | italic)
d_right_text Right text resources
d_right_text_color Text color on the right
d_right_text_size Right text size (default 16sp)
d_right_text_style Set the text style (normal | bold | italic)
d_right_text_padding_end Right text distance right distance
d_right_image Right image resources
d_right_image_width Right image width, height to match the parent layout
d_right_image_padding_end Right picture distance right distance
d_line_height Height of horizontal line at bottom of title bar (default 1px, suggested unit: PX)
d_line_background Bottom line background color of title bar (black by default)
d_title_layout_height Overall title bar height (default: 45DP)
d_title_layout_background Title bar overall background color
d_is_back_view Whether the text and picture on the left are return keys. If so, it has the function of returning to the previous page
d_is_immersive_state_bar Whether the status bar is immersive, default false, (true title bar height includes status bar height)

In Java code

Java code methods 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, and text color
setSubTitle(CharSequence title) Set the subtitle resource
setSubTitleSize(int titleSize) Sets the subheading font size
setSubTitleColor(int titleColor) Sets the subtitle font color
setSubTitleStyle(String title, int titleSize, int titleColor) Set the subheading resource, text size, and text color
setLeftText(String leftText) Set left text
setLeftTextSize(int leftTextSize) Set the text size on the left
setLeftTextColor(int leftTextColor) Set the color of the text on the left
setLeftStyle(String leftText, int leftTextSize, int leftTextColor) Set the left text, text size, and text color
setRightText(String rightText) Set text on the right
setRightTextSize(int rightTextSize) Set the text size on the right
setRightTextColor(int rightTextColor) Set the text color on the right
setTitleClickListener(OnClickListener listener) Title click monitor
setLeftClickListener(OnClickListener listener) Left text and button click to listen
setRightTextClickListener(OnClickListener listener) Click “Listen” on the right
setRightImageClickListener(OnClickListener listener) Click on the right button to listen
setIsLeftBackView(boolean isLeftBackView) Sets whether the text and button on the left are return buttons
setIsHaveLine(boolean haveLine) Sets whether there is a separator at the bottom of the title bar
setLeftBackViewVisible Set the icon on the left to hide
setLeftTextViewVisible Set the left text display to hide
setRightTextViewVisible Set the text display on the right to hide
setRightImageViewVisible Set the icon on the right to hide
setTitleVisible Set title show hide
setSubTitleVisible Set subtitle show hide

The problem

  • To set font color distortion, use: contextCompat.getColor (this, r.color.red)

Update optimization instructions

  • V1.1.1 :(not released)
    • Added setting left and right view is clickable
    • Added title bar double click event, click event callback
  • V1.1.0:
    • Added support for Java code to set all controls to show and hide
  • V1.0.9:
    • Added the function of dynamically setting ICONS on the left and right
    • Add an uninitialized UnsupportedOperationException abnormal hints
  • 1.0.4
    • Fix the bug
    • Support set text style (normal | bold | italic)
  • v1.0.2
    • Added support for subtitle function
    • Optimized the problem of long title display
  • v1.0.1
    • Versatile, general purpose, title bar can be implemented in layout or using Java code;
    • Support for immersive status bar;
    • Support the left back button does not need to manually achieve page return;
    • Support left button, middle title, right button click
    • The left side supports picture + text, single picture, single text; The right side supports separate pictures and text.
    • Versatile, general purpose, title bar can be implemented in layout or using Java code;
    • Support immersive status bar, support the left back button (no need to manually achieve page return), the left support picture + text, picture, text; The right side supports images and text.