导航抽屉ic_drawer和徽标不在操作栏上

时间:2015-02-28 20:54:52

标签: android android-actionbar navigation-drawer android-appcompat

我正在尝试使用带有appcompat和actionbar的NavigationDrawer。我的NavDrawer正在工作,无论是从左侧滑动还是触摸操作栏。

the navigation drawer sample app,操作栏上的home icon显示在与3条纹可绘制相同的“容器”中,表示有侧边菜单。但是在我的应用程序中,home icon显示在此“容器”之外...我正在上传图片以更好地解释发生了什么。此外,home icon看起来比谷歌的示例应用程序大得多,尽管大小相同(xhdpi为96x96)。两个应用程序中的ic_drawer drawable相同。

我不想使用与app启动器图标相同的drawable。

在两个屏幕截图中,我触摸操作栏以打开导航抽屉(请参见突出显示的方块): here is how it looks now here is how I want it

我的清单:

<application
    android:allowBackup="true"
    android:icon="@mipmap/icon"
    android:label="@string/app_name"
    android:theme="@style/MyAppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

我的风格:

<resources>
<style name="MyAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
    <item name="titleTextStyle">@style/TitleTextStyle</item>
    <item name="background">@color/black</item>
    <item name="logo">@drawable/actionbar_logo</item>
    <item name="displayOptions">useLogo|showHome|showTitle</item>
</style>
<style name="TitleTextStyle"
    parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">#FFFFFF</item>
</style>
</resources>

我的MainActivity's onCreate:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new android.support.v4.app.ActionBarDrawerToggle(
            this, mDrawerLayout, R.drawable.ic_drawer, R.string.app_name, R.string.app_name) {
        public void onDrawerClosed(View view) {
        }

        public void onDrawerOpened(View drawerView) {
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
}

感谢您提供任何帮助。

1 个答案:

答案 0 :(得分:1)

导航抽屉示例应用程序显示与api&lt; 21一起使用的旧ActionBarDrawerToggle。这个例子应该更新。

使用新的appcompat 21,模式会发生变化。

操作栏遵循材料设计指南并使用工具栏。 正如您可以阅读here

The use of application icon plus title as a standard layout is 
    discouraged on API 21 devices and newer.

如果您想要应用程序图标,可以使用方法setLogo()

您应该阅读此official post

注意android.support.v4.app.ActionBarDrawerToggle。不推荐使用此类。 您应该使用适用于新工具栏的new class