赞
踩
Android Studio版本不需要跟我的一样,只要检查好JAVA属性(版本)就ok了
win+R,打开CMD命令窗口,输入 java -version 查看java版本是否1.17 版本(或者高过)
(在新建过程尽量不要动这个窗口<最小化也行>,可能建项目的过程有些慢)
如果想省事的直接复制我的代码成功运行,项目名字尽量要跟我的一样 WeChat
如果你要坚持要自己名字的,那你注意我的代码出现 wechat 时看看需不需要更改SDK如果想用低版本的,比如:我想用Android 10,记得在Minimum SDK下更改版本
- <resources xmlns:tools="http://schemas.android.com/tools">
- <!-- Base application theme. -->
- <style name="Theme.WeChat" parent="Theme.AppCompat">
- <!-- Primary brand color. -->
- <item name="colorOnPrimary">@color/white</item>
- <item name="colorOnSecondary">@color/black</item>
- </style>
- </resources>
(具体路径查询看下方)这些是我在iconmonstr网站下载 下载格式 .PNG
(这时候运行一下,如果模拟器能显示出来界面,导航栏多了个东西,就差不多可以了,不过导航栏却动不了,这个是正常的,因为还没有设置到它)
- <?xml version="1.0" encoding="utf-8"?>
- <menu xmlns:android="http://schemas.android.com/apk/res/android">
-
- <item
- android:id="@+id/navigation_WeChat"
- android:icon="@drawable/message"
- android:title="微信" />
-
- <item
- android:id="@+id/navigation_Friend"
- android:icon="@drawable/friend"
- android:title="通讯录" />
- <item
- android:id="@+id/navigation_Search"
- android:icon="@drawable/find"
- android:title="发现" />
- <item
- android:id="@+id/navigation_Self"
- android:icon="@drawable/self"
- android:title="我" />
- </menu>
- <?xml version="1.0" encoding="utf-8"?>
- <navigation 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:id="@+id/mobile_navigation"
- app:startDestination="@+id/navigation_WeChat">
-
- <fragment
- android:id="@+id/navigation_WeChat"
- android:name="com.example.wechat.ui.home.HomeFragment"
- android:label="@string/title_home"
- tools:layout="@layout/fragment_home" />
-
- <fragment
- android:id="@+id/navigation_Friend"
- android:name="com.example.wechat.ui.dashboard.DashboardFragment"
- android:label="@string/title_dashboard"
- tools:layout="@layout/fragment_dashboard" />
-
- <fragment
- android:id="@+id/navigation_Search"
- android:name="com.example.wechat.ui.notifications.NotificationsFragment"
- android:label="@string/title_notifications"
- tools:layout="@layout/fragment_notifications" />
-
- <fragment
- android:id="@+id/navigation_Self"
- android:name="com.example.wechat.ui.home.HomeFragment"
- android:label="@string/title_home"
- tools:layout="@layout/fragment_home" />
- </navigation>
- package com.example.wechat
-
- import android.os.Bundle
- import com.google.android.material.bottomnavigation.BottomNavigationView
- import androidx.appcompat.app.AppCompatActivity
- import androidx.navigation.findNavController
- import androidx.navigation.ui.AppBarConfiguration
- import androidx.navigation.ui.setupActionBarWithNavController
- import androidx.navigation.ui.setupWithNavController
- import com.example.wechat.databinding.ActivityMainBinding
-
- class MainActivity : AppCompatActivity() {
-
- private lateinit var binding: ActivityMainBinding
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
-
- binding = ActivityMainBinding.inflate(layoutInflater)
- setContentView(binding.root)
-
- val navView: BottomNavigationView = binding.navView
-
- val navController = findNavController(R.id.nav_host_fragment_activity_main)
- // Passing each menu ID as a set of Ids because each
- // menu should be considered as top level destinations.
- val appBarConfiguration = AppBarConfiguration(
- setOf(
- R.id.navigation_WeChat,
- R.id.navigation_Friend,
- R.id.navigation_Search,
- R.id.navigation_Self
- )
- )
- setupActionBarWithNavController(navController, appBarConfiguration)
- navView.setupWithNavController(navController)
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。