text stringlengths 1 474 |
|---|
.backgroundMode(FlutterActivityLaunchConfigs.BackgroundMode.transparent) |
.build(context) |
);<code_end> |
<code_start>// Using a new FlutterEngine. |
startActivity( |
FlutterActivity |
.withNewEngine() |
.backgroundMode(FlutterActivityLaunchConfigs.BackgroundMode.transparent) |
.build(this) |
); |
// Using a cached FlutterEngine. |
startActivity( |
FlutterActivity |
.withCachedEngine("my_engine_id") |
.backgroundMode(FlutterActivityLaunchConfigs.BackgroundMode.transparent) |
.build(this) |
);<code_end> |
You now have a FlutterActivity with a transparent background.info Note |
Make sure that your Flutter content also includes a |
translucent background. If your Flutter UI paints a |
solid background color, then it still appears as |
though your FlutterActivity has an opaque background. |
<topic_end> |
<topic_start>Add a Flutter Fragment to an Android app |
This guide describes how to add a Flutter Fragment to an existing |
Android app. In Android, a Fragment represents a modular |
piece of a larger UI. A Fragment might be used to present |
a sliding drawer, tabbed content, a page in a ViewPager, |
or it might simply represent a normal screen in a |
single-Activity app. Flutter provides a FlutterFragment |
so that developers can present a Flutter experience any place |
that they can use a regular Fragment.If an Activity is equally applicable for your application needs, |
consider using a FlutterActivity instead of a |
FlutterFragment, which is quicker and easier to use.FlutterFragment allows developers to control the following |
details of the Flutter experience within the Fragment:FlutterFragment also comes with a number of calls that |
must be forwarded from its surrounding Activity. |
These calls allow Flutter to react appropriately to OS events.All varieties of FlutterFragment, and its requirements, |
are described in this guide.<topic_end> |
<topic_start> |
Add a FlutterFragment to an Activity with a new FlutterEngine |
The first thing to do to use a FlutterFragment is to add it to a host |
Activity.To add a FlutterFragment to a host Activity, instantiate and |
attach an instance of FlutterFragment in onCreate() within the |
Activity, or at another time that works for your app: |
<code_start>public class MyActivity extends FragmentActivity { |
// Define a tag String to represent the FlutterFragment within this |
// Activity's FragmentManager. This value can be whatever you'd like. |
private static final String TAG_FLUTTER_FRAGMENT = "flutter_fragment"; |
// Declare a local variable to reference the FlutterFragment so that you |
// can forward calls to it later. |
private FlutterFragment flutterFragment; |
@Override |
protected void onCreate(Bundle savedInstanceState) { |
super.onCreate(savedInstanceState); |
// Inflate a layout that has a container for your FlutterFragment. |
// For this example, assume that a FrameLayout exists with an ID of |
// R.id.fragment_container. |
setContentView(R.layout.my_activity_layout); |
// Get a reference to the Activity's FragmentManager to add a new |
// FlutterFragment, or find an existing one. |
FragmentManager fragmentManager = getSupportFragmentManager(); |
// Attempt to find an existing FlutterFragment, |
// in case this is not the first time that onCreate() was run. |
flutterFragment = (FlutterFragment) fragmentManager |
.findFragmentByTag(TAG_FLUTTER_FRAGMENT); |
// Create and attach a FlutterFragment if one does not exist. |
if (flutterFragment == null) { |
flutterFragment = FlutterFragment.createDefault(); |
fragmentManager |
.beginTransaction() |
.add( |
R.id.fragment_container, |
flutterFragment, |
TAG_FLUTTER_FRAGMENT |
) |
.commit(); |
} |
} |
}<code_end> |
<code_start>class MyActivity : FragmentActivity() { |
companion object { |
// Define a tag String to represent the FlutterFragment within this |
// Activity's FragmentManager. This value can be whatever you'd like. |
private const val TAG_FLUTTER_FRAGMENT = "flutter_fragment" |
} |
// Declare a local variable to reference the FlutterFragment so that you |
// can forward calls to it later. |
private var flutterFragment: FlutterFragment? = null |
override fun onCreate(savedInstanceState: Bundle?) { |
super.onCreate(savedInstanceState) |
// Inflate a layout that has a container for your FlutterFragment. For |
// this example, assume that a FrameLayout exists with an ID of |
// R.id.fragment_container. |
setContentView(R.layout.my_activity_layout) |
// Get a reference to the Activity's FragmentManager to add a new |
// FlutterFragment, or find an existing one. |
val fragmentManager: FragmentManager = supportFragmentManager |
// Attempt to find an existing FlutterFragment, in case this is not the |
// first time that onCreate() was run. |
flutterFragment = fragmentManager |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.