今天主要是写代码,申请了腾讯云服务器,现在将写的安卓代码放在下面,主要是完成相机调用等
package com.example.team import android.annotation.SuppressLint import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import androidx.fragment.app.Fragment import com.google.android.material.bottomnavigation.BottomNavigationView class MainActivity : AppCompatActivity() { private lateinit var bottomNavigationView: BottomNavigationView private val navListener = BottomNavigationView.OnNavigationItemSelectedListener { item -> var selectedFragment: Fragment? = null when (item.itemId) { R.id.animal -> selectedFragment = AnimalFragment() R.id.plant -> selectedFragment = PlantFragment() } supportFragmentManager.beginTransaction().replace( R.id.fragment_container, selectedFragment!!).commit() true } @SuppressLint("MissingInflatedId") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) bottomNavigationView = findViewById(R.id.bottom_navigation) bottomNavigationView.setOnNavigationItemSelectedListener(navListener) // 默认显示 HomeFragment supportFragmentManager.beginTransaction().replace(R.id.fragment_container, AnimalFragment() ).commit() } }
<?xml version="1.0" encoding="utf-8"?> <!-- activity_main.xml --> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"> <!-- Fragment Container --> <FrameLayout android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@id/bottom_navigation"/> <!-- Bottom Navigation View --> <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottom_navigation" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" app:menu="@menu/bottom_navigation_menu"/> </RelativeLayout>
标签:fragment,selectedFragment,5.24,import,android,bottomNavigationView,id From: https://www.cnblogs.com/gyg1222/p/18216433