我已阅读此https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps。
我的问题是将数据从现有的原生 android 应用程序传递到 flutter 模块(例如:令牌、用户名...等)。所以,我想问一下,有没有什么办法可以在现有的native app中的native code和flutter module中的code之间传递数据?
比如有两个页面,A和B,A是用Java代码写的,B嵌入了flutter view,我在B中没有找到从A传数据到flutter view的方法。
public class TwoActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.two_activity);
//this params passed from HomeActivity
String params = getIntent().getStringExtra("params");
FrameLayout rootView = findViewById(R.id.container);
View flutterView = Flutter.createView(this, getLifecycle(), "service");
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
rootView.addView(flutterView, layoutParams);
}
}
Run Code Online (Sandbox Code Playgroud)
这是 main.dart
void main() => runApp(chooseWidget(window.defaultRouteName));
Widget chooseWidget(String route) {
switch(route) {
case 'service':
return MyFlutterView();
}
}
class MyFlutterView extends StatelessWidget { …Run Code Online (Sandbox Code Playgroud) 我想在操作栏中更改标题的字体。我以编程方式设置了标题,在 xml 中它没有显示任何效果。现在我想更改该标题的字体。我看到了一些与此相关的帖子,但它没有遇到我面临的问题。
这是我的代码。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//SETTING ITS LAYOUT
setContentView(R.layout.activity_start);
Typeface typeface = getResources().getFont(R.font.dancingscriptregular);
//SETTING TITLE OF THE APP IN BLUE COULOR
getSupportActionBar().setTitle(Html.fromHtml("<font color='#1F9FD9'>Expense Manager <font>"));
...
}
Run Code Online (Sandbox Code Playgroud)
现在下一步是什么?,如何使用字体来设置我的标题的字体。
请帮忙!
在 androidMenifest.xml 中
<activity
android:parentActivityName=".StartActivity"
android:name=".ExpenseActivity"
android:fitsSystemWindows="true"
android:label="@string/expenseActivity" <!--This Line is not working-->
android:screenOrientation="portrait"
android:textColor="@color/batteryChargedBlue"
android:theme="@style/ExpenseTheme" />
<activity
Run Code Online (Sandbox Code Playgroud)
费用主题
<style name="ExpenseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/white</item>
<item name="colorPrimaryDark">@color/batteryChargedBlue</item>
<item name="colorAccent">@color/greenBlue</item>
<item name="android:navigationBarColor">@color/batteryChargedBlue</item>
</style>
Run Code Online (Sandbox Code Playgroud)
activity_start.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" …Run Code Online (Sandbox Code Playgroud) fonts android android-actionbar material-design android-toolbar