Home java Custom Toolbar How to make?

Custom Toolbar How to make?

Author

Date

Category

Need to perform such a thing. In the screen header there should be a logo as in the screenshot

Now I have done it so, disabled ActionBar in the markup divided LinNearl to parts by weight and here is the top in which it costs the logo takes 10% of the screen in which I put the picture Logo. I’m new to it so))

Now I want to redo. As far as I understood now the most flexible look in this regard is Toolbar . The question is what, you need to put in the middle of Toolbar , so that it happened as on the screen … I did not find any example in which the image would be in Toolbar with the ability to adjust position of this image in it …

who worked with Toolbar Can you tell me if this is done and if so how?


Answer 1, Authority 100%

Agree that:

“If the second option, then use toolbar for these purposes
no sense, he has another user, let him still remain like
Now, quite a normal solution. “

But if you need to do it, for example, so:

Main Activities:

import android.support.v7.app.appCompatactivity;
Import android.os.Bundle;
Import android.Support.v7.widget.Toolbar;
Public Class MainActivity Extends AppCompatactivity {
  @Override
  PROTECTED VOID OnCreate (Bundle SavedInstanceState) {
    Super.ONCREATE (SavedInstanceState);
    setContentView (R.Layout.Activity_Main);
    SetSupportactionBar ((Toolbar) FindViewByID (R.ID.Tool_Bar));
  }
}

Marking Main Activity:

& lt; xml version = "1.0" encoding = "UTF-8"? & gt;
& lt; linearlayout XMLNS: Android = "http://schemas.android.com/apk/res/android"
  XMLNS: Tools = "http://schemas.android.com/tools"
  Android: Orientation = "Vertical"
  Android: layout_width = "Match_Parent"
  Android: Layout_Height = "Match_Parent"
  Tools: context = "com.vitaliy.testtoolbar.mainactivity" & gt;
  & lt; include
    layout = "@ layout / tool_bar"
    / & gt;
  & lt; TextView
    Android: layout_width = "wrap_content"
    Android: layout_height = "wrap_content"
    Android: Text = "Hello World!" / & gt;
& lt; / linearlayout & gt;

and markup for the Toolbar itself: (tool_bar.xml)

& lt; xml version = "1.0" encoding = "UTF-8"? & gt;
& lt; Android.Support.v7.Widget.Toolbar XMLNS: Android = "http://schemas.android.com/apk/res/android"
  XMLNS: App = "http://schemas.android.com/apk/res-auto"
  XMLNS: Tools = "http://schemas.android.com/tools"
  Android: id = "@ + id / tool_bar"
  Android: layout_width = "Match_Parent"
  Android: layout_height = "wrap_content"
  Android: background = "@ color / colorprimarydark" & gt;
  & lt; relativeLayout
    Android: layout_width = "Match_Parent"
    Android: layout_height = "wrap_content"
    Android: Gravity = "Center"
    & gt;
    & lt; imageview
      Android: paddingtop = "15dp"
      Android: paddingbottom = "15dp"
      App: srccompat = "@ Drawable / Ic_android_24dp"
      Tools: ignore = "MissingPrefix"
      Android: layout_width = "wrap_content"
      Android: layout_height = "wrap_content"
      / & gt;
  & lt; / relativeLayout & gt;
& lt; /android.support.v7.widget.toolbar>

Result:

And you need to not forget to check, so that the topic does not contain Akshnbar

& lt; style name = "apptheme" parent = "theme.appcompat.light.noactionbar" & gt;

Toolbar is used as a regular ViewGroup. And I still listened to the Council, who gave you “pavlofff” in the comments to the question!

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions