【问题标题】:multiple index numbers for getItem() in a single line of code单行代码中 getItem() 的多个索引号
【发布时间】:2020-05-01 08:11:12
【问题描述】:

我编写了这段代码来在导航抽屉中的菜单项右侧添加箭头。我为每个索引分别重复了相同的代码。

     navigationView.getMenu().getItem(0).setActionView(R.layout.arrow_image);
     navigationView.getMenu().getItem(1).setActionView(R.layout.arrow_image);
     navigationView.getMenu().getItem(2).setActionView(R.layout.arrow_image);

有什么方法可以指定所有的索引号(这里是 0,1 和 2),其中箭头应该只出现在一行中?

【问题讨论】:

    标签: android navigationview


    【解决方案1】:

    没有测试,试试这个:

    for(int i=0; i < navigationView.getMenu().size(); i++){      
      navigationView.getMenu().getItem(i).setActionView(R.layout.arrow_image);
    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-19
      • 2017-01-10
      • 2011-03-29
      • 2023-04-01
      • 2017-04-12
      • 2020-01-21
      • 2013-04-06
      相关资源
      最近更新 更多