【问题标题】:Navigation Drawer ic_drawer and logo not together on action bar导航抽屉 ic_drawer 和徽标不在操作栏上
【发布时间】:2015-03-01 23:51:57
【问题描述】:

我正在尝试将 NavigationDrawer 与 appcompat 和操作栏一起使用。通过从左侧滑动或触摸操作栏,我的 NavDrawer 正在工作。

the navigation drawer sample app,操作栏上的home icon 显示在与3-stripes-drawable 相同的“容器”中,表示存在侧边菜单。但是在我的应用程序中,home icon 显示在这个“容器”之外......我正在上传图片以更好地解释正在发生的事情。此外,home icon 看起来比 google 的示例应用程序大得多,尽管尺寸相同(xhdpi 为 96x96)。 ic_drawer drawable 在两个应用程序中是相同的。

我不想使用与应用启动器图标相同的可绘制对象。

在两个屏幕截图中,我都在触摸操作栏以打开导航抽屉(请参见突出显示的方块):

我的清单:

<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 的 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);
}

感谢您对此的任何帮助。

【问题讨论】:

  • 你在使用 app compat 21 吗?
  • @GabrieleMariotti 是的,com.android.support:appcompat-v7:21.0.3

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


【解决方案1】:

导航抽屉示例应用程序显示与 api

使用新的 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

【讨论】:

  • 谢谢。如果我使用setLogo(),它会像第一张图片一样显示徽标(在可点击的正方形之外)。我还是想保留旧的 logo+title 模式……
  • 那么解决办法是什么?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多