In conjunction with Material Design of Baidu map

Blog on Baidu Map SDK has written three, and three inside the previous blog, I described how to map their own area of ​​the display, how to display their location, orientation sensor to indicate how to combine cell phone direction. Today's blog content on the map SDK Baidu content does not matter how complex, just talk about how to combine some of the controls under the Material Design to add some small knowledge Baidu map.

Toolbar control to place using the toggle button, as shown:

Write pictures described here

We want to put some icon in the title bar surface, different content appears after clicking the icon unused.

First of all we need to know is that under normal circumstances, we generate App title bar above is Actionbar control, not the Toolbar control. How Actionbar controls into a Toolbar control it?
First we need to understand why the default is Action control? Open the res / layout / values / style.xml we can see:

parent="Theme.AppCompat.Light.DarkActionBar"

We can see this one, if we've replaced it with the following sentence, then Actionbar was removed.

parent="Theme.AppCompat.Light.NoActionBar

Then we can add a Toolbar control in the layout inside.

<android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"


            android:background="?attr/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

Then there is the added activity

Toolbar toolbar=(Toolbar)findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

In this case, we instantiate a Toolbar object, and () method can Actionbar Toolbar by setSupportActionBAr has the same function.

However, we should note that the above two lines of code must be placed

SDKInitializer.initialize(getApplicationContext());
        setContentView(R.layout.activity_main);

Back, otherwise, we may not see the desired results (I do not see how, but also a long time to try out the change in the title bar icon settings).

Toolbar control to do the title bar has come out, we have to add some face in the title bar icon.

Very simple, we just need to create a toolba.xml in the menu, and then add the item to the top.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        app:showAsAction="always"
        android:id="@+id/myid"
        android:icon="@drawable/nav_location"
        android:title="我的位置"/>
    <item
        app:showAsAction="always"
        android:id="@+id/satellite"
        android:icon="@drawable/nav_task"
        android:title="卫星地图"/>

    <item
        app:showAsAction="always"
        android:id="@+id/trafficmap"
        android:icon="@drawable/traffic"
        android:title="实时地图"/>


</menu>

Here we use the android: icon = "" reference icon, here we also set up a title, but we can not see the text of the title, it is because we used the app: showAsAction = "always", this parameter indicates the item we write It will appear in the title bar, and in the form of icons.
So far, we run on the phone, there should be similar to the image above situation can occur, but if you feel there are any questions, we can explore together, after all he is still white one.
Write pictures described here

Published 37 original articles · won praise 10 · views 10000 +

Guess you like

Origin blog.csdn.net/OneLinee/article/details/78396609
Recommended