我真的很想知道为什么我无法在当前构建中使用导航抽屉看到徽章/计数器。但是在其他构建中,如新创建的应用程序导航活动,它正在显示。我关注了Hari的博客:https://medium.com/@harivigneshjayapalan/android-adding-badge-or-count-to-the-navigation-drawer-84c93af1f4d9#.tknc8q6wy
是否因为gradle build?
我对android很新,我迷失了我想念的......
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:checkableBehavior="single">
<item android:id="@+id/nav_dashboard"
android:icon="@drawable/ic_dashboard_black_24dp"
android:title="Nav1 title"/>
<item android:id="@+id/nav_bookshelf"
app:actionViewClass="android.widget.TextView"
app:showAsAction="always"
android:icon="@drawable/ic_book_black_24dp"
android:title="My Books" />
<item android:id="@+id/nav_results"
android:icon="@drawable/ic_insert_chart_black_24dp"
android:title="Nav3 title" />
<item android:id="@+id/nav_settings"
android:icon="@drawable/ic_settings_black_24dp"
android:title="Nav4 title" />
</group>
</menu>
在Navigation Activity类onCreate方法:
TextView navbookshelf=(TextView)MenuItemCompat.getActionView(navigationView.getMenu().findItem(R.id.nav_bookshelf));
navbookshelf.setGravity(Gravity.CENTER_VERTICAL);
navbookshelf.setTypeface(null, Typeface.BOLD);
navbookshelf.setTextColor(getResources().getColor(R.color.colorAccent));
navbookshelf.setText("1");
答案 0 :(得分:0)
AppCompat
下的23.0
依赖关系似乎存在问题。根据{{3}} ActionView set to an item in support NavigationView not showing并查看您提供的帖子的源代码(特别是this answer),您应该将依赖关系更新为23.1.1
,如下所示:< / p>
dependencies {
...
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}