【问题标题】:findViewById (int) in Activity cannot be applied to (int, android.support.v7.widget.ToolbarActivity中的findViewById(int)不能应用到(int, android.support.v7.widget.Toolbar
【发布时间】:2015-08-06 18:21:14
【问题描述】:

所以我一直关注Slidnerd tutorial on the Navigation Drawer。当我试图创建一个 ActionBarDrawerToggle 实例来指定ActivityDrawerLayoutToolbar 时,就会出现问题。

(NavigationDrawerFragment)getSupportFragmentManager().findFragmentById(R.id.fragment_nav_drawer); 
drawerFragment.setUp((DrawerLayout) findViewById (R.id.drawer_layout, toolbar); 

我在 (R.id.drawer_layout,工具栏) 中遇到错误。错误提示:" Activity 中的 findViewById (int) 无法应用于 (int, android.support.v7.widget.Toolbar"

我尝试了一个建议的解决方案,即导入 android.support.v4.app.Fragment,但即使尝试了这个问题仍然存在,我什至反之亦然。如果需要,我也愿意发布我的相关代码。

有谁知道如何解决这个问题?

感谢所有帮助。谢谢,祝您有美好的一天!

【问题讨论】:

    标签: android android-fragments navigation-drawer android-toolbar drawerlayout


    【解决方案1】:

    这个错误是因为findViewById 只接受一个int,而不是一个int 和一个Toolbar。应该这样使用:

    drawerFragment.setup((DrawerLayout)findViewById(R.id.drawer_layout), toolbar);
    

    【讨论】:

    • @PolycapNyakundi - 我已更新我的代码以显示整行。
    • 太棒了。因为如果你能使它正确,那就太好了。很高兴为您提供帮助
    【解决方案2】:

    只需用这个替换你的行,错误就消失了......

     drawerFragment.setUp((DrawerLayout)findViewById(R.id.drawer_layout), toolbar);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-11
      • 2020-08-26
      相关资源
      最近更新 更多