首页 > 其他分享 >5.24

5.24

时间:2024-05-27 20:22:29浏览次数:30  
标签:fragment selectedFragment 5.24 import android bottomNavigationView id

今天主要是写代码,申请了腾讯云服务器,现在将写的安卓代码放在下面,主要是完成相机调用等

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

相关文章

  • 算法学习笔记——动态规划.最长上升/下降子序列 2024.5.24
    LanqiaoOJ 773这道题是一道动态规划的题目,主要考察最长上升/下降子序列,难度中等,但是对思维的考察比较重要,特别是如何解决其第二问题目描述某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统。但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以......
  • 5.24
    packagecom.example.computerbookstore;importandroidx.appcompat.app.AppCompatActivity;importandroid.content.Intent;importandroid.database.Cursor;importandroid.database.sqlite.SQLiteDatabase;importandroid.database.sqlite.SQLiteException;importandroi......
  • 5.24每日总结
    学习了sqlserver用管理器创建触发器实现如下安全性和完整性①定义course表中credit属性为“3”的缺省sql复制代码ALTERTABLECourseADDCONSTRAINTDF_Course_CreditDEFAULT3FORCcredit;②建立course与sc表间来维护参照完整性而使用的一个级联删除触发器、......
  • Connecting to github.com (github.com)|20.205.243.166|:443... failed: Connection
    今天使用ubuntu虚拟机编译buidroot代码时出现一些压缩包无法从github下载,如下图: 可是拷贝上图log中的下载链接到windows浏览器进行打开会自动进行下载成功,如粘贴该链接 https://github.com/winshining/nginx-http-flv-module/archive/v1.2.8/nginx-http-flv-......
  • 已知IP地址是192.168.5.121,子网掩码是255.255.255.248,求网络地址和主机地址
    方法1首先,将Ip地址转换为二进制:192.168.5.121转换为二进制:11000000.10101000.00000101.01111001然后将子网掩码转换成二进制:255.255.255.248转换为二进制:11111111.11111111.11111111.11111000网络地址=IP地址&子网掩码192.168.5.121&255.255.255.248=192.168.5.12......
  • 5.24学习总结
    MySQL导入数据本章节我们为大家介绍几种简单的MySQL导入数据命令。 1、mysql命令导入使用mysql命令导入语法格式为:mysql-u用户名-p密码<要导入的数据库数据(runoob.sql)实例:#mysql-uroot-p123456<runoob.sql以上命令将将备份的整个数据库runoob.......
  • 5.24 面向对象案例分析六
    classBook{//类的名称要以class开头,否则报错,并且提示不到这行代码!!!privateintbid;privateStringtitle;privatedoubleprice;privatestaticintcount=0;publicBook(Stringtitle,doubleprice){count++;this.bid=count;......
  • 5.24
    题目描述:定义一个时间类,小时和分钟是其两个私有成员数据。输入一个起始时间和一个结束时间(起始时间早于结束时间),通过运算符重载-(减号),计算这两个时间相隔多少分钟。说明:这两个时间在同一天之内,且采用24小时计时分式,即从00:00-23:59。输入格式:测试输入包含若干测试用例,每......
  • 5.24每日总结
      今天完成了python的一个餐厅点餐系统。  功能:实现菜品的添加、修改、删除,订单的增加、删除、清空,计算总价。     ......
  • 5.24 3.2
    一、问题如果整数A的全部因子(包括1,不括A本身)之和等于B;且整数B的全部因子(包括1不包括B本身)之和等于A,则将整数A和B称为亲密数。求3000以内的全部亲密数。二、分析根据问题描述,该问题可以转化为:给定整数A,判断A是否有亲密数。为解决该问题,首先定义变量a,并为......