tah*_*qvi 8 java android android-fragments android-navigation android-architecture-navigation
我正在使用 android 导航组件来导航片段。我可以通过在 Main Activity 中使用此代码轻松设置操作栏:
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
Run Code Online (Sandbox Code Playgroud)
但是如果我想在某些片段中隐藏 supportActionbar 那么最好的方法是什么?
Zai*_*ain 11
对于要隐藏的片段,SupportActionBar可以将其隐藏在onResume()with 中.hide(),然后在onStop()with 中再次显示.show()
@Override
public void onResume() {
super.onResume();
ActionBar supportActionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar();
if (supportActionBar != null)
supportActionBar.hide();
}
@Override
public void onStop() {
super.onStop();
ActionBar supportActionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar();
if (supportActionBar != null)
supportActionBar.show();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2564 次 |
| 最近记录: |