У меня есть действие, содержащее два фрагмента, теперь я хочу использовать один из фрагментов в качестве ящика навигации в приложении (вставьте / выведите при нажатой кнопке)
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/_40sdp"
android:id="@+id/rl_header"
android:background="#714ECA">
<RelativeLayout
android:layout_width="@dimen/_20sdp"
android:layout_height="@dimen/_20sdp"
android:id="@+id/rl_menubutton"
android:layout_marginLeft="@dimen/_10sdp"
android:layout_centerVertical="true">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/iv_menu"
android:src="@drawable/menu"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/iv_back"
android:src="@drawable/back"
android:visibility="gone"/>
</RelativeLayout>
<TextView
android:id="@+id/tv_city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="cursive"
android:text="Montreal"
android:layout_centerInParent="true"
android:textColor="@color/white"
android:textSize="@dimen/_20ssp"
android:textStyle="bold"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/rl_header">
<RelativeLayout
android:layout_width="@dimen/_100sdp"
android:layout_height="@dimen/_20sdp"
android:id="@+id/rl_logo"
android:background="@color/colorPrimaryDark">
<ImageView
android:layout_width="@dimen/_20sdp"
android:layout_height="@dimen/_20sdp"
android:src="@drawable/flag"
android:layout_marginTop="@dimen/_5sdp"
android:layout_marginLeft="@dimen/_2sdp"
android:layout_alignParentLeft="true"
android:id="@+id/iv_logo"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/iv_logo"
android:layout_marginTop="@dimen/_5sdp"
android:text="CAWeather"
android:textStyle="bold"
android:fontFamily="sans-serif-thin"
android:textColor="@color/white"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/_3sdp"/>
</RelativeLayout>
<FrameLayout
android:layout_width="@dimen/_100sdp"
android:layout_height="match_parent"
android:id="@+id/f_cities"
tools:layout="@layout/cities_fragment"
android:layout_below="@+id/rl_logo"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/f_cities"
android:id="@+id/f_weather"
tools:layout="@layout/weather_fragment"/>
</RelativeLayout>
</RelativeLayout>
MainActivity.java
package com.example.finalproject;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentTransaction;
public class MainActivity extends FragmentActivity {
FrameLayout f_cities;
public static TextView tv_city;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
init();
Fragment city = new city_fragment();
FragmentTransaction Transaction = getSupportFragmentManager().beginTransaction();
Transaction.replace(R.id.f_cities, city);
Transaction.commit();
}
private void init() {
f_cities = (FrameLayout)findViewById(R.id.f_cities);
tv_city = (TextView)findViewById(R.id.tv_city);
}
}
Я много гуглю, получаю только результаты, связанные с использованием ящиков навигации внутри фрагментов. Любая помощь будет оценена.