android工具栏和抽屉:后面的图标永远不会显示

时间:2015-07-28 15:30:34

标签: android navigation-drawer toolbar

我试图在汉堡包和背面图标之间实现动画。

但是,当抽屉打开时,总会显示汉堡包图标。

activity.xml:

<LinearLayout   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:orientation="vertical" >

<android.support.v7.widget.Toolbar  
    android:id="@+id/toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:theme="?actionBarTheme" />

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/black" >

    <FrameLayout
        android:id="@+id/fragment_container_1"
        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:paddingTop="5dp"
        android:choiceMode="singleChoice" 
        android:background="@color/light_black" />

</android.support.v4.widget.DrawerLayout> 

活动内的代码:

protected static ActionBarDrawerToggle actionBarDrawerToggle;
protected static DrawerLayout drawerLayout;
protected static ListView drawerList;   

...

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);             
    toolbar.setTitle(getString(R.string.app_name));        
    toolbar.setTitleTextColor(getResources().getColor(R.color.white));
    toolbar.showOverflowMenu();
    setSupportActionBar(toolbar);

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);    
    drawerList = (ListView) findViewById(R.id.left_drawer);
    if(drawerLayout != null)            // Portrait
    {           
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);

        ListViewAdapter listViewAdapter = new ListViewAdapter(this, fragments_titles);
        listViewAdapter.addAll(fragments_titles);

        drawerList.setAdapter(listViewAdapter);
        drawerList.setOnItemClickListener(new DrawerItemClickListener());

        actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open, R.string.drawer_close);
        /*ctionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close);*/

        drawerLayout.setDrawerListener(actionBarDrawerToggle);                 
        actionBarDrawerToggle.syncState();
     }

这是我的风格和主题:

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar" >
    <!-- Theme customizations available in newer API levels can go in res/values-vXX/styles.xml, 
         while customizations related to backward-compatibility can go here. -->
</style>

<!-- Application theme, all customizations that are NOT specific to a particular API-level can go here. -->        
<style name="AppMainTheme" parent="AppBaseTheme" >

    <item name="windowActionBar">false</item>
    <item name="drawerArrowStyle">@style/MyTheme.DrawerStyle</item>
    <item name="actionBarTheme">@style/MyTheme.ToolbarStyle</item>
    <item name="android:buttonStyle">@style/Button_CustomStyle</item>     
    <item name="android:textViewStyle">@style/TextView_CustomStyle</item>
    <item name="android:editTextStyle">@style/EditText_CustomStyle</item>

</style>

<style name="MyTheme.DrawerStyle" parent="Widget.AppCompat.DrawerArrowToggle" >
    <item name="spinBars">true</item>
    <item name="color">@color/white</item>
</style>

<style name="MyTheme.ToolbarStyle" parent="ThemeOverlay.AppCompat.ActionBar" >
    <item name="android:textColorPrimary">@android:color/white</item>
</style>

我检查了很多问题。

由于

1 个答案:

答案 0 :(得分:0)

You can try these libraries to implement this easily instead of writing your own code :

DrawerArrowDrawable

LDrawer

material-menu