How to change navigation draver icon size? - android

I was looking for different ways to do this using styles or programmatically, but not one way worked. Is it possible to increase the size of this icon in any way?
Toolbar:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:background="#color/color_primary"
android:layout_width="match_parent"
android:layout_height="#dimen/toolbar_h">
<RelativeLayout
android:id="#+id/toolbar_wrapper"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:clickable="true"
android:focusable="true"
....
Activity:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<include
layout="#layout/toolbar"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="end">
....
Activity code:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_skeleton)
val toggle = object : ActionBarDrawerToggle(this, drawer, toolbar, R.string.nd_open, R.string.nd_close) {}
drawer.addDrawerListener(toggle)
toggle.syncState()
}

You can change the size of Navigation Drawer icons by overriding design_navigation_icon_size attribute in dimens.xml
<dimen name="design_navigation_icon_size" tools:override="true">40dp</dimen>

If you want to add a custom nav icon to your action bar you should be doing as follows -
onCreate(Bundle savedInstanceState){
......
setSupportActionBar(binding.toolbar);
if (
getSupportActionBar() != null
) {
setTitle("");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.icon_menu);
}
......
This will set a custom drawable button to your action bar. and as you are setting it itself, now make it as per your size. or even if you want you can set different icon for different screen size.

Related

My Fragment appears underneath the Toolbar regardless of how I change constraints

No matter how I add constraints, nothing changes in terms of my Fragment which contains a RecyclerView.
I have added a toolbar:
OnCreate in MainActivity
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)//TODO find inconsistencies
val demo = DemoDataBuilder()
// Set the toolbar as support action bar
setSupportActionBar(toolbar)
// Now get the support action bar
val actionBar = supportActionBar
// Set toolbar title/app title
actionBar!!.title = "AwezaMed"
// Set action bar/toolbar sub title
actionBar.subtitle = "App subtitle"
// Set action bar elevation
actionBar.elevation = 4.0F
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_black_24dp)
toolbar.setNavigationOnClickListener { _ -> onBackPressed()}
startCategoryHome(savedInstanceState)
}
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"
android:id="#+id/root_layout">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="?attr/colorPrimary"
android:minHeight="57dp"
android:padding="1dp"
app:layout_constraintTop_toTopOf="parent"
app:subtitleTextColor="#f5fbff"
app:titleTextColor="#fff" />
<fragment
android:id="#+id/categoyList_fragment"
android:name="za.co.aweza.awezamediphrases.fragments.CategoryListFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="112dp"
app:layout_constraintTop_toBottomOf="#+id/toolbar"
tools:layout="#layout/fragment_hcp_category" />
</android.support.constraint.ConstraintLayout>
You'll notice that in the layout code above, I have a very farfetched constraint that I tried to use.
Here is how it appears in designView:
But regardless of anything I try, the first cell of the RV in the Fragment sits mostly underneath the toolbar. What am I missing?
instead of fragment put this in your xml:
`<FrameLayout
android:id="#+id/frameLayout_fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="#id/toolbar" />`
Replace the frame layout with any fragment you want using this function:
` fun openFragment(fragment: Fragment) {
val transaction = supportFragmentManager.beginTransaction()
transaction.replace(R.id.frameLayout_fragment_container, fragment)
transaction.addToBackStack(null)
transaction.commit()
}`
#EliodeBeirut's answer worked, but I found that changing the layout activity_main.xml from Constraint layout to Linear Layout worked as well.

Status bar overlaps toolbar on pre-lollipop but not on Lollipop / Marshmallow

This is the issue I am encountering
On pre-lollipop devices I have the following issue
On Lollipop and Marshmallow devices everything appears fine
I am trying to create the translucent status bar effect when opening the navigation drawer.
On Marshmallow and lollipop devices this is working fine.
Here is my code
activity_base.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawerLayout"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ToolbarStyle"
app:theme="#style/ToolbarStyle" />
<FrameLayout
android:id="#+id/activity_content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<include layout="#layout/view_navigation_drawer_layout" />
</android.support.v4.widget.DrawerLayout>
view_navigation_drawer_layout.xml
<android.support.design.widget.NavigationView
android:id="#+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/nav_header" />
<ListView
android:id="#+id/lst_menu_items"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</android.support.design.widget.NavigationView>
Note that I do the above because of the answer to this question NavigationView and custom Layout
Notice that both layouts have the android:fitsSystemWindows="true"
I thought maybe its because I include the layout so I tried copying the whole layout into the activity layout. Did not help
I also have this styles xml file in my values-v19 directory (for KitKat and above)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="MaterialDesign">
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
I made a solution to this issue. However, my solution requires a BaseActivity that hijacks the layout as stated in this blog post http://mateoj.com/2015/06/21/adding-toolbar-and-navigation-drawer-all-activities-android/
here is my code
public class BaseActivity extends AppCompatActivity {
#Override
public void setContentView(int layoutResID) {
ViewGroup baseView = (ViewGroup) getLayoutInflater().inflate(R.layout.activity_base_with_drawer);
FrameLayout activityContainer = (FrameLayout) baseView.findViewById(R.id.activity_content);
getLayoutInflater().inflate(layoutResID, activityContainer, true);
super.setContentView(layoutResID);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
if (useToolbar()) { //Does the activity have a toolbar?
toolbar.setFitsSystemWindows(true); //toolbar will stretch underneath the status bar and because it naturally has a semi translucent background, it will assume a darker color of the toolbar which is usually the color primary.
setSupportActionBar(toolbar); //Set the toolbar
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
} else {
toolbar.setVisibility(View.GONE);
activityContainer.setFitsSystemWindows(true); //No toolbar so we set the container to have the fitsSystemWindow attribute to ensure contents do not overlay the system window such as status bar and navigation bar.
TypedValue outValue = new TypedValue();
boolean doesThemeHaveTranslucentWindow = getTheme().resolveAttribute(android.R.attr.windowIsTranslucent, outValue, true); //Check if the current activity theme has translucent window, this includes SearchActivity
if (!doesThemeHaveTranslucentWindow) { //If it does not then set the container background to colour primary to have the same effect as the toolbar being there and avoid a white status bar. We do not want to do this for translucent windows otherwise they would not be see through
activityContainer.setBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimary));
}
}
}
And this is the layout
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ToolbarStyle"
app:theme="#style/ToolbarStyle" />
<FrameLayout
android:id="#+id/activity_content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<include layout="#layout/view_navigation_drawer_layout" />
</android.support.v4.widget.DrawerLayout>
FitsSystemWindows is no longer set in any of the XML layouts. This is done in the setContentViewMethod of the BaseActivity class.
If the activity does not have a toolbar, the activity container has the fitsSystemWindow attribute set to true otherwise, the toolbar has it applied.
If the activity does not have a toolbar, its container layout has a background colour set to the colour primary.
Why I do this is because when you set fitsSystemWindows on your toolbar it stretches underneath the status bar and because the status bar naturally has a semi translucent background, it will assume a darker color of the toolbar which is usually the color primary so we do this for the activity container to have the same effect.
Now there is a use-case I had in my app where I had an activity with a transparent window background which I check. If not true, the activity container has this colour set.
Not sure if its the best solution but its working well for me so far on Marshmallow, pre-lollipop and pre-KitKat too :P . Hope it helps out others.

Custom Action Bar in Android does not match parent

Hello everyone I'm try to make custom action bar. My codes below. Everything is good at the right side of Action Bar but at the left side custom action bar does not match. How can I solve this problem.
Thanks in helpings.
EDIT 1 :
My main activity xml, it has not got anything interest with action bar but I could not figure out where the problem is
activity_main.xml
<RelativeLayout 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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
android:id="#+id/hh">
</RelativeLayout>
Here is my custom action bar xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button"
android:background="#ffff2301" />
</RelativeLayout>
My Java Code;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setCustomView(R.layout.action_bar);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
}
}
You are using setCustomView() on the default toolbar provided by the theme. Custom views are meant to be loaded in the toolbar space that is not occupied by other views (logo, title, overflow menu..).
So your custom layout becomes part of the toolbar, and does not replace it. So either:
You want things to be this way. In this case your issue is just background color. I don't know how you set the custom view to be yellow, but try adding android:background="#color/transparent" to the RelativeLayout and switch the whole toolbar color to yellow instead. The room in the left will be eventually loaded with navigation icons, so you want it to be there.
You want to (I'd suggest to) use the Toolbar API which makes it easier to add custom views. This is done this way:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/custom_toolbar"/>
<RelativeLayout android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
</LinearLayout>
And then, in custom_toolbar.xml,
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:abc="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent">
<!-- you can add any custom view here -->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button"
android:background="#ffff2301" />
</android.support.v7.widget.Toolbar>
In your onCreate() you now have to call:
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar tb = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(tb);
}
}

Fragment overlaps the AppCompat toolbar

I'm working with the v7 support library and trying to have a navigation drawer on the left.
As read elsewhere I set up:
DrawerTest.java: The main activity that holds the drawer, into which I load my Toolbar
with setSupportActionBar(), from a custom XML layout that holds
just the Toolbar;
toolbar.xml: A XML layout holding the toolbar;
activity_drawer_listview.xml: A DrawerLayout XML resource, that holds containers for my fragment
(a FrameLayout <including> the layout mentioned in 2.) and for the
navigation drawer (a ListView);
FragmentTest.java: Some really simple fragment code, extending Fragment;
fragment_test_layout.xml: Some really simple fragment layout, with just a TextView inside.
I'll paste some code here, anyway my problem is that the fragment layout seems to start from the top of the screen, and not from the bottom of the Toolbar. Any text put in 5. will overlap the app title on the action bar. Where am I wrong?
(1.) DrawerTest.java
public class DrawerTest extends ActionBarCompat {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_drawer_listview);
DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
Toolbar tb = (Toolbar) findViewById(R.id.toolbar_main2);
ActionBarDrawerToggle abDrawerToggle = new ActionBarDrawerToggle(
this, drawerLayout, tb,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close )
{
// onDrawerClosed() { ... }
// onDrawerOpened() { ... }
};
drawerLayout.setDrawerListener(abDrawerToggle);
setSupportActionBar(tb);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
abDrawerToggle.syncState();
//code to load my fragment
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.frame_layout_test, new FragmentTest()).commit();
}
}
(3.) activity_drawer_listview.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="#+id/drawer_layout"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context="miav.ciotole.DrawerTest">
<FrameLayout android:id="#+id/frame_layout_test" android:layout_width="match_parent"
android:layout_height="match_parent" >
<include layout="#layout/toolbar"/> <!-- What is this line about? -->
</FrameLayout>
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
(4.) FragmentTest.java
public class FragmentTest extends Fragment {
public FragmentTest() { }
#Override
public View onCreateView(LayoutInflater infl, ViewGroup container, Bundle SavedInstanceState) {
View rootView = infl.inflate(R.layout.fragment_test_layout, container, false);
return rootView;
}
}
(5.) fragment_test_layout.xml
<RelativeLayout 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"
// padding ...
>
<TextView android:id="#+id/section_label" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world"/>
Note: I found some questions (and answers), but in most cases, the issue was related to AppCompat versions < 19, which is not my case.
Note2: I am inheriting from Theme.AppCompat.NoActionBar, as I'm setting the toolbar on runtime. Probably I could solve inheriting from Theme.AppCompat and avoid using setSupportActionBar(), but if possible I would stay with the actual configuration, as it makes easier to control the ActionBar.
The reason is because you place it in a frame layout and then you add the fragment ontop of the toolbar. you need to do something like this
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<FrameLayout
android:id="#+id/left_drawer"
android:layout_width="325dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#FFFFFF"/>
</android.support.v4.widget.DrawerLayout>
Add this line in your FrameLayout
app:layout_behavior="#string/appbar_scrolling_view_behavior"
You put the toolbar in the same Framelayout (with the id = frame_layout_test). FrameLayout overlaps views.
I guess you are trying to do something like this:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="#layout/toolbar"/>
<!-- I don't know what your Toolbar layout is -->
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
tools:context="miav.ciotole.DrawerTest">
<FrameLayout android:id="#+id/frame_layout_test"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
The layout from above takes a linear layout and aligns the framelayout (where you will inflate your framgemt) below the toolbar ...
This lines
android:layout_height="0dp"
android:layout_weight="1"
says that the DrawerLayout should take the remaining height below the toolbar.
However, if you want to display a traditional actionbar / toolbar, you don't have to add a toolbar in the xml layout. You simply can change the Theme of the activity to #style/Theme.AppCompat.Light.DarkActionBar
This is very straight forward and easy. Just follow what I tried to say below.
You replace any View by using:
**
getFragmentManager().beginTransaction()
.replace(R.id.blankFragment, new SettingsFragment())
.commit();
**
//Here, blackFragment is id of FrameLayout View. You replace FrameLayout View with Fragment's Layout. Note: It should be FrameLayout or FrameLayout's derivatives Layout.
My whole code is:
1) SettingsActivity.java
**
public class SettingsActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fragment);
Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar2);
mToolbar.setTitle("Settings");
//// remove the left margin from the logo
mToolbar.setPadding(2, 0, 0, 0);//for tab otherwise give space in tab
mToolbar.setContentInsetsAbsolute(0, 0);
setSupportActionBar(mToolbar);
// Display the fragment as the main content
getFragmentManager().beginTransaction()
.replace(R.id.blankFragment, new SettingsFragment())
.commit();
}
}
**
2) activity_fragment.xml
**
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="match_parent"
android:fitsSystemWindows="true"
android:orientation="horizontal">
<!--scroll|snap-->
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/statusbar"
android:minHeight="?attr/actionBarSize"
app:theme="#style/ThemeOverlay.AppCompat.ActionBar" />
<FrameLayout
android:id="#+id/blankFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize"
android:layout_gravity="top"
android:fitsSystemWindows="true"
android:orientation="horizontal" />
</FrameLayout>
**
You can see my Screen after I replaced FrameLayout's View with Fragment's View
I have two activities and attach one fragment to them. In first activity it is shown right, while in second it overlaps Toolbar. Though android:layout_marginTop="?android:attr/actionBarSize" in a layout of the fragment may be a solution, I found an error.
Because Kotlin caches ids of views of layouts (instead of findViewById(R.id.some_id) you can write some_id), there is a big problem. Every time you should be very careful when copy an activity or a fragment. So, every time check your imports and attached layouts.
I copied FirstActivity to SecondActivity, copied activity_first to activity_second, but forgot to change:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_first) // Don't forget to change.
Similarly, in a fragment don't forget:
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_yours, container, false)
So, in my imports I had:
import kotlinx.android.synthetic.main.activity_second.*
In this case toolbar referenced to activity_second, while activity_first was actually attached. Then the fragment moved upper - just below the Toolbar. In most cases Kotlin never shows any problem with cached ids during compile or run time. It's a big pain.

Unable to setup navdrawer to go over toolbar in the new 5.0 SDK using appcompat-v7

Has anyone successfully got the navigation drawer to open over top of a toolbar that is being used with setSupportActionBar(toolbar)? I am using Theme.AppCompat.Light.NoActionBar.
If I make the Toolbar a child of the Drawerlayout in my xml, then the toolbar fills the entire screen no matter what height I set it to. The only other thing I could think of doing was wrapping my drawerlayout and toolbar in another parent layout and placing the toolbar outside of the navdrawer, but then the navdrawer opens up below the toolbar.
I was also not successful in getting the hamburger icon to transition to an arrow when using the navdrawer. I am using the new ActionBarDrawerToggle from the v7 compat library as well.
So I created a new test project targetting api21 only and used the following XML, and it also has the same problem where the toolbar fills the entire screen. The navdrawer DOES open over top of it in with this code.
Any help is greatly appreciated. Thanks
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<fragment android:id="#+id/navigation_drawer"
android:layout_width="#dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:name="com.example.testnav.NavigationDrawerFragment"
tools:layout="#layout/fragment_navigation_drawer"/>
<Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar_actionbar"
android:layout_width="match_parent"
android:layout_height="?android:actionBarSize"
android:background="#43599a"/>
</android.support.v4.widget.DrawerLayout>
Here is my toolbar code from my activity:
final DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
Toolbar mActionBarToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
if (mActionBarToolbar != null) {
setActionBar(mActionBarToolbar);
}
if (mActionBarToolbar != null) {
mActionBarToolbar.setNavigationIcon(R.drawable.ic_drawer);
mActionBarToolbar.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (mDrawerLayout.isDrawerOpen(Gravity.START)) {
mDrawerLayout.closeDrawer(Gravity.START);
} else {
mDrawerLayout.openDrawer(Gravity.START);
}
}
});
}
It can be a solution.
<!-- Main layout -->
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/headerbar"
android:orientation="vertical">
<!--Toolbar-->
<include layout="#layout/toolbar"/>
<include layout="#layout/main_container" />
</LinearLayout>
<!-- Nav drawer -->
<include layout="#layout/navdrawer" />
Another way is to put the toolbar inside the layout which you use in your main container.

Categories

Resources