Я создаю действие (MainActivity.kt) с помощью «android.support.design.widget.BottomNavigationView», которое имеет несколько вкладок.Когда пользователь касается вкладки, то «BottomNavigationView.OnNavigationItemSelectedListener» должен представить соответствующий фрагмент.
Вопрос:
Как установить во время выполнения в методе onCreateView другой фрагмент, чемопределяется в файле макета атрибутом «android: name».
MainActivity.kt
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)
}
Layout / ActivityMain.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.developer.myapplication.Locator"
android:id="@+id/fragment"
/>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation"
app:layout_constraintTop_toBottomOf="@+id/fragment"
app:layout_constraintStart_toStartOf="parent"/>
</android.support.constraint.ConstraintLayout>