0

I have an activity with bottomAppBar and a floatingActionButton anchored on it but after calling onBackPressed() method, it is flowing on the bar, and I need something like what I said.

Here is my code:

class AppUiActivity: AppCompatActivity() {
    private lateinit var navController: NavController
    private var backPressedTime: Long = 0
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val binding = FragmentAppUiBinding.inflate(layoutInflater)
        setContentView(binding.root)
        val navHostFragment =
            supportFragmentManager.findFragmentById(R.id.uifragment) as NavHostFragment
        navController = navHostFragment.findNavController()
        binding.Expenses.setOnClickListener {
            findNavController(this, R.id.uifragment).navigate(R.id.expenses)
        }
        binding.details.setOnClickListener {
            findNavController(this, R.id.uifragment).navigate(R.id.details2)
        }
        binding.calculate.setOnClickListener {
            findNavController(this, R.id.uifragment).navigate(R.id.calculate2)
        }
        binding.total.setOnClickListener {
            findNavController(this, R.id.uifragment).navigate(R.id.total2)
        }
        binding.floatingActionButton.setOnClickListener {
            Intent(this, ExpenseDialog::class.java).also {
                startActivity(it)
                overridePendingTransition(R.anim.from_bottom, R.anim.from_bottom)
            }
        }
    }
    override fun onBackPressed() {
        val navHostFragment =
            supportFragmentManager.findFragmentById(R.id.uifragment) as NavHostFragment
        navController = navHostFragment.findNavController()
        if (navController.currentDestination?.id == R.id.chooseIcon) {
            findNavController(R.id.uifragment).navigate(R.id.action_chooseIcon_to_addOtherCategory)
        } else {
            val params = CoordinatorLayout.LayoutParams(
                CoordinatorLayout.LayoutParams.MATCH_PARENT,
                CoordinatorLayout.LayoutParams.MATCH_PARENT
            )
            val r: Resources = resources
            val px = TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP,
                55F,
                r.displayMetrics
            ).toInt()
            params.setMargins(0,0,0,px)
            findViewById<FragmentContainerView>(R.id.uifragment)?.layoutParams = params
            findViewById<BottomAppBar>(R.id.bottom_bar)!!.visibility = View.VISIBLE
            findViewById<FloatingActionButton>(R.id.floatingActionButton).visibility = View.VISIBLE
            if (backPressedTime + 3000 > System.currentTimeMillis()) {
                super.onBackPressed()
                findNavController(this, R.id.uifragment).navigate(R.id.details2)
                finish()
            } else {
                findNavController(this, R.id.uifragment).navigate(R.id.details2)
            }
            backPressedTime = System.currentTimeMillis()
        }
    }
}

After onBackPressed() After onBackPressed() called

Before onBackPressed() Before onBackPressed() called

guipivoto
  • 18,327
  • 9
  • 60
  • 75
  • the anchor of the fab looks identical in both images. The difference to me is the background of the bottom bar – Ivo Feb 03 '22 at 10:40
  • so apparantly it's called the fabCradle. It seems you aren't the first one with that issue: https://github.com/material-components/material-components-android/issues/1334 – Ivo Feb 03 '22 at 10:44
  • yes, this is my question – adnan salem Feb 03 '22 at 12:55

0 Answers0