-
-
Save c4software/aebb8f467c229e186d88a04b13a3f406 to your computer and use it in GitHub Desktop.
La version à l'ancienne
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".ui.bottom.BottomActivity"> | |
<androidx.fragment.app.FragmentContainerView | |
android:id="@+id/frame" | |
android:layout_width="0dp" | |
android:layout_height="0dp" | |
app:layout_constraintBottom_toTopOf="@id/bottom_navigation" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toTopOf="parent" /> | |
<com.google.android.material.bottomnavigation.BottomNavigationView | |
android:id="@+id/bottom_navigation" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintStart_toStartOf="parent" | |
app:menu="@menu/bottom_navigation_menu" /> | |
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BottomActivity : AppCompatActivity() { | |
companion object { | |
fun getStartIntent(context: Context): Intent { | |
return Intent(context, BottomActivity::class.java) | |
} | |
} | |
private var page1Instance = Page1.newInstance() | |
private var page2Instance = Page2.newInstance() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_bottom) | |
showFragment(page1Instance) | |
bottom_navigation.setOnNavigationItemSelectedListener { item -> | |
when (item.itemId) { | |
R.id.page_1 -> { | |
// Item 1 action | |
showFragment(page1Instance) | |
true | |
} | |
R.id.page_2 -> { | |
// Item 1 action | |
showFragment(page2Instance) | |
true | |
} | |
else -> false | |
} | |
} | |
} | |
private fun showFragment(fragment: Fragment) { | |
supportFragmentManager.commit { | |
setReorderingAllowed(true) | |
replace(R.id.frame, fragment, fragment.tag) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Page1 : Fragment() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
} | |
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | |
// Inflate the layout for this fragment | |
return inflater.inflate(R.layout.fragment_page1, container, false) | |
} | |
companion object { | |
fun newInstance() = Page1() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment