如何加上"菜单"指示灯旁边的操作栏的程序图标? [英] How to add "menu" indicator next to Action Bar's app icon?

查看:190
本文介绍了如何加上"菜单"指示灯旁边的操作栏的程序图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前至少的Gmail和YouTube Android应用使用侧面菜单(抽屉式导航? )打开通过刷卡,或通过单击应用程序图标(home键):

At least Gmail and Youtube Android apps use a side menu (navigation drawer?) that opens by swiping, or by clicking the app icon (home button):

是在Android SDK中的现成的部分上面的截图中的菜单指示/图标? (或自定义图标,谷歌在他们的应用程序使用?)在任何情况下,什么是让你的home键,看起来像最简单的方法,也就是说,像它会打开一个菜单?

Is the menu indicator / icon in the screenshot above a ready-made part of Android SDK? (Or a custom icon Google uses in their apps?) In any case, what's the easiest way to get your home button to look like that, i.e., like it opens a menu?

targetSdkVersion 18; 的minSdkVersion 14)

最后得到它的工作。什么是缺少对我来说是1)<一href="http://android-ui-utils.google$c$c.com/hg/asset-studio/dist/icons-nav-drawer-indicator.html">the实际图标 2)递延呼叫 syncState() ActionBarDrawerToggle

Finally got it working. What was missing for me was 1) the actual icon and 2) deferred call to syncState() on the ActionBarDrawerToggle.

推荐答案

要创建类似的实现/在你的应用程序看起来你应该使用 ActionBarDrawerToggle 和设置您的自定义图标,指示旁边的动作条home键。例如:

To create similar implementation / look in your application you should use ActionBarDrawerToggle and set your custom icon as indicator next to ActionBar home button. For example :

import android.app.ActionBar;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;

private void setUpDrawerToggle(){
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the navigation drawer and the action bar app icon.
    mDrawerToggle = new ActionBarDrawerToggle(
            this,                             /* host Activity */
            mDrawerLayout,                    /* DrawerLayout object */
            R.drawable.ic_drawer,             /* nav drawer image to replace 'Up' caret */
            R.string.navigation_drawer_open,  /* "open drawer" description for accessibility */
            R.string.navigation_drawer_close  /* "close drawer" description for accessibility */
    ) {
        @Override
        public void onDrawerClosed(View drawerView) {
            invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
        }
    };

    // Defer code dependent on restoration of previous instance state.
    // NB: required for the drawer indicator to show up!
    mDrawerLayout.post(new Runnable() {
        @Override
        public void run() {
            mDrawerToggle.syncState();
        }
    });

    mDrawerLayout.setDrawerListener(mDrawerToggle);
}

其中, R.drawable.ic_drawer 实际上是作为指标来使用的图标。你可以找到它在 Android的资产工作室的;看<一href="http://android-ui-utils.google$c$c.com/hg/asset-studio/dist/icons-nav-drawer-indicator.html#theme=light&color=33b5e5,40">Navigation抽屉指示灯

Where R.drawable.ic_drawer is actually the icon to use as indicator. You can find it in Android Asset Studio; see Navigation Drawer Indicator.

引用

  1. <一个href="http://developer.android.com/reference/android/support/v4/app/ActionBarDrawerToggle.html">ActionBarDrawerToggle
  2. 创建导航抽屉
  1. ActionBarDrawerToggle
  2. Creating a Navigation Drawer

这篇关于如何加上&QUOT;菜单&QUOT;指示灯旁边的操作栏的程序图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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