ActionBarToggle汉堡箭头不起作用

时间:2015-06-14 12:36:56

标签: android

我已经实现了所有内容的v7版本并将旋转值更改为true。汉堡还没有变成明星。我试着看一些示例代码,但所有代码都有相似的代码。我尝试使用工具栏将主类扩展到Activity类。它运作良好。

 barToggle= new ActionBarDrawerToggle(this,mDrawerLayout,R.string.drawer_open,R.string.drawer_close){
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);

        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);

        }


    };


    myBar = getSupportActionBar();
    myBar.setDisplayShowTitleEnabled(false);
    myBar.setDisplayHomeAsUpEnabled(true);
    myBar.setHomeButtonEnabled(true);

这是我的stlye xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/primaryColor</item>
    <item name="colorPrimaryDark">@color/primaryColorDark</item>


    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>

</style>

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
    <item name="spinBars">true</item>
    <item name="color">@android:color/white</item>
</style>

1 个答案:

答案 0 :(得分:0)

尝试使用此

public class MyActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);

    DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer);
    android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
    ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(
            this,
            drawerLayout,
            toolbar,
            R.string.open,
            R.string.close
    )

    {
        public void onDrawerClosed(View view)
        {
            super.onDrawerClosed(view);
            invalidateOptionsMenu();
            syncState();
        }

        public void onDrawerOpened(View drawerView)
        {
            super.onDrawerOpened(drawerView);
            invalidateOptionsMenu();
            syncState();
        }
    };
    drawerLayout.setDrawerListener(actionBarDrawerToggle);

    //Set the custom toolbar
    if (toolbar != null){
        setSupportActionBar(toolbar);
    }

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    actionBarDrawerToggle.syncState();
}

}