1 package androidx.appcompat.app; 2 /* 3 * Copyright (C) 2016 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 import android.os.Bundle; 19 import android.view.LayoutInflater; 20 import android.view.View; 21 import android.view.ViewGroup; 22 23 import androidx.annotation.Nullable; 24 import androidx.appcompat.test.R; 25 import androidx.appcompat.testutils.BaseTestActivity; 26 import androidx.fragment.app.Fragment; 27 28 29 public class FragmentContentIdActivity extends BaseTestActivity { 30 31 @Override onCreate(Bundle savedInstanceState)32 protected void onCreate(Bundle savedInstanceState) { 33 super.onCreate(savedInstanceState); 34 35 getSupportFragmentManager().beginTransaction() 36 .add(android.R.id.content, new FragmentA()) 37 .commit(); 38 } 39 40 @Override getContentViewLayoutResId()41 protected int getContentViewLayoutResId() { 42 // We don't want to set a layout 43 return 0; 44 } 45 replaceWithFragmentB()46 public void replaceWithFragmentB() { 47 getSupportFragmentManager().beginTransaction() 48 .replace(android.R.id.content, new FragmentB()) 49 .commit(); 50 } 51 52 public static class FragmentA extends Fragment { 53 @Override onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)54 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, 55 @Nullable Bundle savedInstanceState) { 56 View view = new View(getContext()); 57 view.setId(R.id.fragment_a); 58 return view; 59 } 60 } 61 62 public static class FragmentB extends Fragment { 63 @Nullable 64 @Override onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)65 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, 66 @Nullable Bundle savedInstanceState) { 67 View view = new View(getContext()); 68 view.setId(R.id.fragment_b); 69 return view; 70 } 71 } 72 73 } 74 75 76 77