Need to do this thing. In the header of the screen should be the logo as in the screenshot

enter image description here

Now I did it like this, turned off the ActionBar in the markup, divided LinnearL into parts by weight, and here the top in which the logo stands is 10% of the screen in which I put the logo as a picture. I am a beginner therefore did so))

Now I want to redo it. As I understand it now, the most flexible view in this regard is the ToolBar . The question is, you need to put the logo in the middle of the ToolBar to make it like on the screen ... I did not find a single example in which they would put an image in the ToolBar with the ability to adjust the position of this image in it ...

Who worked with ToolBar can you tell if this can be done and if so, how?

  • 2
    Toolbar is a normal ViewGroup, add for example FrameLayout to it, well, and then it’s understandable) - Andrey Kasyanov
  • one
    You are going to use the Toolbar also for its intended purpose - navigation in the application, menu, and so on. or just this picture above is necessary. If the second option, then use the Toolbar for this purpose does not make any sense, it has a different use, Let it then remain, as it is now, a completely normal solution. - pavlofff
  • @pavlofff It will be necessary to add another NavigationDrawer , I will use it for its intended purpose, but according to the statement of work, you need to attach a logo to the top ... - Aleksey Timoshchenko
  • And plus to that, it seems to me that the toolbar will look better on different screens - Aleksey Timoshchenko

1 answer 1

I agree that:

"If the second option, then use the Toolbar for this purpose does not make any sense, it has a different use, Let it remain, as it is now, a completely normal solution."

But if you need to do this, you can for example:

The main activity:

 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 the main activation:

 <?xml version="1.0" encoding="utf-8"?> <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"> <include layout="@layout/tool_bar" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" /> </LinearLayout> 

And the markup for the ToolBar itself: (tool_bar.xml)

 <?xml version="1.0" encoding="utf-8"?> <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"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" > <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" /> </RelativeLayout> </android.support.v7.widget.Toolbar> 

Result:

enter image description here

And you need to remember to check that the topic does not contain akshnbar

 <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 

ToolBar - used as a normal ViewGroup. And I still listened to the advice that gave you "pavlofff" in the comments to the question!

  • It will be necessary to add another NavigationDrawer , I will use it for its intended purpose, but according to the statement of work, you need to attach a logo to the top ... Now I’ll try your advice, if I succeed, I’ll write how it looks. And plus to that, it seems to me that the toolbar will look better on different screens - Aleksey Timoshchenko
  • Yes, I think this is what you need - Aleksey Timoshchenko
  • @AlekseyTimoshchenko, glad that it helped))) - Maybe_V