如何在左上角Android DrawerLayout中添加3行图标 [英] How to add 3 lines icon in left top corner Android DrawerLayout

查看:247
本文介绍了如何在左上角Android DrawerLayout中添加3行图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写新的应用程序,我想将我的 drawerLayout 图标外观更改为典型的3条水平线。如果我点击它,Icon应该将他的外观改为箭头。现在我一直有一个箭头图标。

I'am writing new app and I want to change my drawerLayout icon look to typical 3 horizontal lines. If I click on it, Icon should change his look to arrow. Now I have an arrow icon all the time.

package pl.nieruchalski.scrumfamily;

package pl.nieruchalski.scrumfamily;

import android.app.Activity;
import android.content.res.Configuration;
import android.os.PersistableBundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;

public class MainActivity extends Activity {

    private ActionBarDrawerToggle drawerToggle;
    private DrawerLayout drawerLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
        drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.openDrawer, R.string.closeDrawer);
        drawerLayout.addDrawerListener(drawerToggle);
        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setHomeButtonEnabled(true);
    }

    @Override
    public void onPostCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onPostCreate(savedInstanceState, persistentState);
        drawerToggle.syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        drawerToggle.onConfigurationChanged(newConfig);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if(drawerToggle.onOptionsItemSelected(item))
            return true;
        return super.onOptionsItemSelected(item);
    }
}


推荐答案

你'重写错误的 onPostCreate()方法,所以 drawerToggle.syncState(); 永远不会被调用,并且切换永远不会在 ActionBar 上放置自己的图标。

You're overriding the wrong onPostCreate() method, so drawerToggle.syncState(); never gets called, and the toggle never puts its own icon on the ActionBar.

您需要覆盖 onPostCreate( )仅包含 Bundle 参数的方法;没有 PersistableBundle 参数。

You need to override the onPostCreate() method with only the Bundle parameter; no PersistableBundle parameter.

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    drawerToggle.syncState();
}

这篇关于如何在左上角Android DrawerLayout中添加3行图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆