Change action bar icon position - java

I want to display the menu icon to left of the toolbar and the search icon to be in the actual place of the menu icon
This is my main.xml file inside the main folder
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/my_search"
android:icon="#drawable/ic_search_black_24dp"
android:title="search"
app:showAsAction="always">
</item>
<item
android:id="#+id/my_menu_icon"
android:icon="#drawable/ic_menu_black_24dp"
android:title="side_menu"
app:showAsAction="always">
</item>
</menu>
This is the result of this page:
my result
And this is my MainActivity.java:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);//affect the menu file to the main activity and call this last one
return true;
}
}

I prefer use Toolbar instead of ActionBar, and Customize layout in xml form. you can change AppTheme like this inside /src/main/res/values/style.xml:
<style name="AppTheme" parent="Base.Theme.AppCompat.Light">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
do not forget to set AppTheme in manifest, like this:
<application
android:theme="#style/AppTheme"
//and other properties
</application>
then you can use android Toolbar inside layouts:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:orientation="horizontal">
<ImageButton
android:id="#+id/menu_btn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="#drawable/ic_menu_black_24dp""/>
<TextView
android:id="#+id/title"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:gravity="left"
android:text="App Title"
android:textSize="16dp"
android:textStyle="bold"/>
<ImageButton
android:id="#+id/search_btn"
android:layout_width="?attr/actionBarSize"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="#drawable/ic_search_black_24dp"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
// and other views
// .
// .
// .
</android.support.design.widget.CoordinatorLayout>

Related

set Label Alignment in navigation Fragments

I want the label(toolbar title) to be aligned centered.What should I do? I have reffered to some logics and didn't find them effective and they also didn't work. So kindly guide me through it.
This is the Navigation File:
<?xml version="1.0" encoding="utf-8"?>
<navigation 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/mobile_navigation"
app:startDestination="#id/current_weather_fragment">
<fragment
android:id="#+id/current_weather_fragment"
android:name="com.example.wheatherapp.UI.Weather.CurrentWeather.CurrentWeatherFragment"
android:label="current_weather_fragment"
tools:layout="#layout/current_weather_fragment" />
<fragment
android:id="#+id/future_weather_fragment"
android:name="com.example.wheatherapp.UI.Weather.FutureWeather.FutureWeatherListFrag.FutureWeatherFragment"
android:label="future_weather_fragment"
tools:layout="#layout/future_weather_fragment" />
<fragment
android:id="#+id/future_detail_weather"
android:name="com.example.wheatherapp.UI.Weather.FutureWeather.FutureDetailFrag.FutureDetailWeather"
android:label="future_detail_weather_fragment"
tools:layout="#layout/future_detail_weather_fragment" />
<fragment
android:id="#+id/setting_fragment"
android:name="com.example.wheatherapp.UI.Setting.SettingFragment"
android:label="SettingFragment" />
</navigation>
This is the MainActvity.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".UI.MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:theme="#style/ToolbarTheme">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="?colorPrimary"
/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.fragment.app.FragmentContainerView
android:id="#+id/nav_host_frag"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="#id/appbar_layout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="#id/bottom_nav"
app:navGraph="#navigation/mobile_navigation"
app:defaultNavHost="true"
android:name="androidx.navigation.fragment.NavHostFragment" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="#menu/bottom_nav_menu"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
This is the image in which i want the title to be aligned centered:
the uploaded one
Style.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.WheatherApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_200</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_200</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="ToolbarTheme" parent="ThemeOverlay.MaterialComponents.ActionBar">
<item name="android:textColorPrimary">#color/white</item>
<item name="android:textColorSecondary">#EEEEEE</item>
<item name="android:gravity">center_vertical|center_horizontal</item>
<item name="background">?colorPrimary</item>
</style>
</resources>
1) Add Textview for your toolbar title into your tag which is located in MainActivity.xml in your case.
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:theme="#style/ToolbarTheme">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="?colorPrimary">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Borrowers"
android:textColor="#color/white"
android:textSize="18dp" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
2) Add toolbar to your MainActivity.java in onCreate() method.
//set toolbar
Toolbar toolbar = findViewById(R.id.borrowerstoolbar_main);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(null);

Why are menu items aligned so strangely on the ActionMenuView inside the toolbar?

Why are menu items aligned so strangely on the toolbar?
It behaves even more strangely with smaller toolbar:
I use the following code:
MainActivity.java:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
//getMenuInflater().inflate(R.menu.menu_main_right, menu);
Toolbar toolbar = findViewById(R.id.toolbar);
ActionMenuView toolbarLeft = toolbar.findViewById(R.id.toolbarLeft);
getMenuInflater().inflate(R.menu.menu_main_left, toolbarLeft.getMenu());
return true;
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="#style/ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.v7.widget.ActionMenuView
android:id="#+id/toolbarLeft"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:gravity="center_vertical|start"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.v7.widget.Toolbar>
</android.support.constraint.ConstraintLayout>
styles.xml:
<resources>
<style name="ActionBar">
<item name="android:background">#drawable/toolbar</item>
<item name="actionMenuTextColor">#color/colorToolbarText</item>
</style>
</resources>
menu_main_left.xml:
<?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"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="#+id/actionAdd"
android:title="Add"
app:showAsAction="always"/>
<item
android:id="#+id/actionDetails"
android:title="Details"
app:showAsAction="always"/>
<item
android:id="#+id/actionLegend"
android:title="Legend"
app:showAsAction="always"/>
<item
android:id="#+id/actionSettings"
android:title="Settings"
app:showAsAction="always"/>
</menu>

How to add action bar to second activity but not to first one

I have two activities, First is simple Login page in which I disabled action bar as I don't need it there, second activity is the user feed section where I want to add action bar with text or search option and app drawer maybe. How do I add the action bar to second activity but not to first?
You should make app theme like this to have no actionbars by default.
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorPrimary</item>
</style>
In your AndroidManifest.xml file, in <application> tag add this line:
android:theme="#style/AppTheme"
And if you need action bar on some activity just add this to your activity layout file:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="owo.owocar.driver.rides_history_entity.ui.HistorySingleActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:background="#drawable/gradient"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:background="#drawable/gradient"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_history_single" />
</android.support.design.widget.CoordinatorLayout>
You can define a different theme for the 2nd activity.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
...
</style>
<style name="LoginTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
</style>
I would use a NoActionBar style for the Apptheme:
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Then in the layout of the activity where you want an action bar, you can include it:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.xxx.xxx.Activity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/fragment" />
</android.support.design.widget.CoordinatorLayout>
This produces the bar on the top of your activity, without any buttons/text/menu. Create a toolbar inside your Activity.java:
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Hope this helps.
You can simply now use a Toolbar
<android.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:title="Hello World"
android:elevation="4dp"
android:id="#+id/my_toolbar"
/>
Then set it as an action bar in your Activity.java file
Toolbar myToolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
...
myToolbar = findViewById(R.id.my_toolbar);
setActionBar(myToolbar);
}
Note that the Toolbar that is being used in the example above is android.widget.Toolbar and not androidx.appcompat.widget.Toolbar

Issue between android:windowLightStatusBar and Navigation Drawer

I have set android:windowLightStatusBar to true to display black icons and text on status bar inside my app as picture below.
However, the Navigation Drawer no longer fit to the screen, see the picture below. This is because to ensure android:windowLightStatusBar works, android:windowTranslucentStatus must be set to false. Any workaround? App like Google Calendar seem to work fine with this feature.
Here's my main activity's XML
<android.support.v4.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorToolbarBackground"
android:fitsSystemWindows="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/app_bar" />
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:background="#color/colorWhite"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="#menu/navigation_view_items" />
</android.support.v4.widget.DrawerLayout>
Remove this line from layout.xml
android:fitsSystemWindows="true"
And add this to styles-v21.xml
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
in styles.xml
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
in Manifest.xml add this in your Activity Main
android:theme="#style/AppTheme.NoActionBar"
And wrap AppBarLayout tag into this:
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<!-- Here AppBarLayout ecc -->
</android.support.design.widget.CoordinatorLayout>
<!-- Here NavigationView ecc -->
AppBarLayout must have
android:theme="#style/AppTheme.AppBarOverlay"

Toolbar does not display (briefly shows up before disappearing)

I am trying to make an action bar (through toolbar) with a navigation drawer, however I only manage to get the navigation drawer part working. When the app loads in the emulator, it does seem that the toolbar shows up on the screen for a fraction of a second before it disappears, showing a screen without a toolbar. How do i get the toolbar to show up/not disappear on load?
This is how it looks like:
styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorPrimaryDark</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
styles.xml (v21)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- API 14 theme customizations can go here. -->
<item name="android:statusBarColor">#color/colorPrimaryDark</item>
<item name="colorPrimary">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorPrimaryDark</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
</resources>
MainActivity.java (trimmed away excess codes)
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
public class MainActivity extends AppCompatActivity implements OnMarkerClickListener {
Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
...
}
main_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:layout_height="wrap_content"
android:layout_width="match_parent"
layout="#layout/toolbar_layout"
/>
</LinearLayout>
<android.support.design.widget.NavigationView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/navigation_view"
android:layout_gravity="start"
app:menu="#menu/drawer_menu"
>
</android.support.design.widget.NavigationView>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/mainfrag"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="#layout/main_layout" />
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
toolbar.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"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:id="#+id/toolbar"
android:background="?attr/colorPrimaryDark"
android:minHeight="?attr/actionBarSize"
android:fitsSystemWindows="true"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
</android.support.v7.widget.Toolbar>
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
...
As Ajay mentioned that DrawerLayout should only contain two layouts so I am editing some of your codes to fulfill the requirements and I think this would work just give it a try
main_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<include
android:layout_height="wrap_content"
android:layout_width="match_parent"
layout="#layout/other_layout"/>
<android.support.design.widget.NavigationView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/navigation_view"
android:layout_gravity="start"
app:menu="#menu/drawer_menu"/>
</android.support.v4.widget.DrawerLayout>
Now add your other layouts to another layout file
other_layout.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbar"
android:background="?attr/colorPrimaryDark"
android:minHeight="?attr/actionBarSize"
android:fitsSystemWindows="true"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<FrameLayout
android:id="#+id/mainfrag"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="#layout/main_layout" />
</FrameLayout>
</LinearLayout>
main_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:layout_height="wrap_content"
android:layout_width="match_parent"
layout="#layout/toolbar_layout"
/>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/mainfrag"
android:layout_width="match_parent"
android:layout_height="0dp" //Changed Value
android:layout_weight="1"> //Added
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="#layout/main_layout" />
</FrameLayout>
</LinearLayout>
<android.support.design.widget.NavigationView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/navigation_view"
android:layout_gravity="start"
app:menu="#menu/drawer_menu"
>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
DrawerLayout Should only contain two child Views, first the main content and then the drawer view.
Creating a Navigation Drawer

Categories