导航抽屉项目图标不显示原始颜色
2022-08-31 07:44:14
我试图在导航抽屉的菜单中的某个项目旁边显示一个图标,但由于某种原因,图标始终显示为灰色而不是原始颜色(棕色)。有没有办法防止这种情况发生,以显示图标的原始颜色?
主要活动.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;
}
});
}
}
drawer_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>