packagecom.example.toutiao.activity;importandroid.os.Bundle;importandroidx.appcompat.app.AppCompatActivity;importandroidx.navigation.NavController;importandroidx.navigation.Navigation;importandroidx.navigation.ui.NavigationUI;importcom.example.toutiao.R;importcom.google.android.material.bottomnavigation.BottomNavigationView;publicclassMainActivityextendsAppCompatActivity{@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);BottomNavigationViewnavView=findViewById(R.id.nav_view);// binding the bottom_nav and fragment to transfer
NavControllernavController=Navigation.findNavController(this,R.id.nav_host_fragment_activity_main);NavigationUI.setupWithNavController(navView,navController);}}
packagecom.example.toutiao.ui.video;importandroid.os.Bundle;importandroidx.fragment.app.Fragment;importandroid.view.LayoutInflater;importandroid.view.View;importandroid.view.ViewGroup;importcom.example.toutiao.R;/**
* A simple {@link Fragment} subclass.
* Use the {@link VideoFragment#newInstance} factory method to
* create an instance of this fragment.
*/publicclassVideoFragmentextendsFragment{// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
privatestaticfinalStringARG_PARAM1="param1";privatestaticfinalStringARG_PARAM2="param2";// TODO: Rename and change types of parameters
privateStringmParam1;privateStringmParam2;publicVideoFragment(){// Required empty public constructor
}/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment VideoFragment.
*/// TODO: Rename and change types and number of parameters
publicstaticVideoFragmentnewInstance(Stringparam1,Stringparam2){VideoFragmentfragment=newVideoFragment();Bundleargs=newBundle();args.putString(ARG_PARAM1,param1);args.putString(ARG_PARAM2,param2);fragment.setArguments(args);returnfragment;}@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);if(getArguments()!=null){mParam1=getArguments().getString(ARG_PARAM1);mParam2=getArguments().getString(ARG_PARAM2);}}@OverridepublicViewonCreateView(LayoutInflaterinflater,ViewGroupcontainer,BundlesavedInstanceState){// Inflate the layout for this fragment
returninflater.inflate(R.layout.fragment_video,container,false);}}
項目心得
由於這次的項目因為我本身是安卓零基礎,而我卻使用了一週的時間將整體的 Code 邏輯架構寫好了,這是因為我會使用 Google 用關鍵字搜索,StackOverFlow 大多數時候都能給我比較好的答案,在做項目之前我頂多是有了做過 Qt C++ 的基礎,所以了解了一下安卓的組件生命週期還有哪些控件和布局,我就直接邊做邊學,我覺得這樣子對我的成長和動手能力提升很多,也謝謝字節跳動客戶端開發的大哥們一直提點我的不足。最終得以完成這個項目。