左侧滑菜单+menu item icon图标显示为灰

【1】menu   item   icon图标显示为灰色解决问题

左侧滑菜单+menu item icon图标显示为灰_第1张图片

 

如上所示,因为是在navigationview里的所以在获取到他的ID后加上

navigationView.setItemIconTintList(null);

左侧滑菜单+menu item icon图标显示为灰_第2张图片

问题解决,图标显示出来了

左侧滑菜单+menu item icon图标显示为灰_第3张图片

 

【2】左侧滑菜单

参考博主文章:https://blog.csdn.net/s1674521/article/details/62220187

主活动代码:

public class MainActivity extends Activity implements View.OnClickListener {
    private DrawerLayout drawerLayout;
    private NavigationView navigationView;
    private ImageView menu;
    private String hhh_item="";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        initWindow();
        drawerLayout = findViewById(R.id.activity_na);
        navigationView =  findViewById(R.id.nav);
        navigationView.setItemIconTintList(null);
        menu=  findViewById(R.id.menu);
        menu.setOnClickListener(this);
        navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                //item.setChecked(true);
                Toast.makeText(MainActivity.this,item.getTitle().toString(),Toast.LENGTH_SHORT).show();
                drawerLayout.closeDrawer(navigationView);
                return true;
            }

        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.menu://点击菜单,跳出侧滑菜单
                if (drawerLayout.isDrawerOpen(navigationView)){
                    drawerLayout.closeDrawer(navigationView);
                }else{
                    drawerLayout.openDrawer(navigationView);
                }
                break;
        }
    }

    private void initWindow() {//初始化窗口属性,让状态栏和导航栏透明

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

            int statusColor = Color.parseColor("#1976d2");

        }
    }

    public void test(View view){
        Intent intent=new Intent(MainActivity.this,NewActivity.class);
        startActivity(intent);
    }

}

activity_main.xml:



    

    

    

   左侧滑菜单+menu item icon图标显示为灰_第4张图片

左侧滑菜单+menu item icon图标显示为灰_第5张图片

 

 

你可能感兴趣的:(Android,左滑菜单,menu)