如何在应用程序中检测pri资源是否可用

时间:2018-08-14 09:31:27

标签: c# uwp uwp-xaml resource-loading

我已经将PRI资源包括在UWP应用程序中,并通过ResourceLoader进行即时加载,如下代码所示

lateinit var toolbar: Toolbar

private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
    when (item.itemId) {
        R.id.navigation_home -> {
            toolbar.title = "Home"
            val homeFragment = HomeFragment.newInstance()
            openFragment(homeFragment)
            return@OnNavigationItemSelectedListener true
        }
        R.id.navigation_manage_tasks -> {
            toolbar.title = "Manage Tasks"
            val manageTasksFragment = ManageTasksFragment.newInstance()
            openFragment(manageTasksFragment)
            return@OnNavigationItemSelectedListener true
        }
        R.id.navigation_add_tasks -> {
            //toolbar.title = "Add Task"
            val addTaskFragment = AddTaskFragment.newInstance()
            openFragment(addTaskFragment)
            return@OnNavigationItemSelectedListener true
        }
        R.id.navigation_profile -> {
            //toolbar.title = "Profile"
            val profileFragment = ProfileFragment.newInstance()
            openFragment(profileFragment)
            return@OnNavigationItemSelectedListener true
        }
    }
    false
}

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    toolbar = findViewById(R.id.action_bar)
    setSupportActionBar(toolbar)

    //toolbar = supportActionBar!!
    val bottomNavigation: BottomNavigationView = findViewById(R.id.navigationView)
    BottomNavigationViewHelper.disableShiftMode(bottomNavigation)
    bottomNavigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)

    //
    // Show the First Fragmnet on load - One time only
    //
    val manager = supportFragmentManager
    var fragment: Fragment? = manager.findFragmentById(R.id.container)

    if (fragment == null) {
        fragment = HomeFragment()
        manager.beginTransaction().add(R.id.container, fragment).commit()
    }
}




private fun openFragment(fragment: Fragment) {
    val transaction = supportFragmentManager.beginTransaction()
    transaction.replace(R.id.container, fragment)
    transaction.addToBackStack(null)
    transaction.commit()
}

如何检测应用程序中是否有文件。使用上述代码时,如果文件不可用,则应用程序将花费更多时间来处理此代码。如果文件可用,则会立即加载应用程序

谢谢

0 个答案:

没有答案