14.我的home页面的代码如下:
@Route(path = RouterPath.ROUTER_HOME) public class MainActivity extends AppCompatActivity { @Autowired() String home_msg; private TextView mTvHome; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); ARouter.getInstance().inject(this); mTvHome = (TextView) findViewById(R.id.tv_home); mTvHome.setText(home_msg+""); } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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" android:gravity="center"> <TextView android:id="@+id/tv_home" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
15.在mine的逻辑代码如下:
@Route(path = RouterPath.ROUTER_MINE) public class MainActivity extends AppCompatActivity { @Autowired String mine_msg; private TextView mTvMine; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ARouter.getInstance().inject(this); setContentView(R.layout.activity_mine); mTvMine = (TextView) findViewById(R.id.tv_mine); mTvMine.setText(mine_msg); } }
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.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:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <TextView android:id="@+id/tv_mine" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="这是默认的我的界面!!!!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout>
16:在store下的代码:
@Route(path= RouterPath.ROUTER_STORE) public class MainActivity extends AppCompatActivity { @Autowired String store_msg; private TextView mTvStore; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_store); ARouter.getInstance().inject(this); mTvStore = (TextView) findViewById(R.id.tv_store); mTvStore.setText(store_msg); } }
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.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:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <TextView android:id="@+id/tv_store" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="这是商店的默认界面!!!!!!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout>
哈哈哈,最后警告一下,新建的module下的布局文件的名字不要全部一样的,到时候有冲突的额!!!接下来我们就可以试着运行项目了。