我正在尝试为导航抽屉的菜单中的项目旁边显示一个图标,但是由于某种原因,该图标始终显示为灰色,而不是原始颜色(棕色)。有什么方法可以防止这种情况发生,以显示图标的原始颜色?
MainActivity.java
public class MainActivity extends AppCompatActivity {
private DrawerLayout mDrawerLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
if (navigationView != null) {
setupDrawerContent(navigationView);
}
}
private void setupDrawerContent(NavigationView navigationView) {
navigationView.setNavigationItemSelectedListener(
new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
mDrawerLayout.closeDrawers();
return true;
}
});
}
}
cabinet_view.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Section">
<menu>
<item
android:id="@+id/navigation_item_1"
android:icon="@drawable/ic_browncircle"
android:title="Sub item 1" />
</menu>
</item>
</menu>
.setColorFilter(MY_BROWN_COLOR)
这种观点?
ic_browncircle
?