Android Studio Kotlin 简单实现微信主界面UI

这篇具有很好参考价值的文章主要介绍了Android Studio Kotlin 简单实现微信主界面UI。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

准备编写环境  Y v Y(修改中,仅供参考)

        操作系统:

                        windows11

        Android Studio 属性 :

                        文件版本 2023.2.0.0

                        产品版本 2023.2.0.AI-232.10227.8.2321._BUILD_NUMBER_


        JAVA属性:

                         java version "17.0.10" 2024-01-16 LTS
                        Java(TM) SE Runtime Environment (build 17.0.10+11-LTS-240)
                        Java HotSpot(TM) 64-Bit Server VM (build 17.0.10+11-LTS-240, mixed mode, sharing)

Android Studio版本不需要跟我的一样,只要检查好JAVA属性(版本)就ok了        

        win+R,打开CMD命令窗口,输入 java -version 查看java版本是否1.17 版本(或者高过)

开始新建项目

        1、选择新建一个项目 New Project,在 Templates 选择到 Phone and Tablet

        (一般这里不用选择,一进来默认就选定了)

        2、找到并选择 Bottom Navigition Views Activity,然后下一步Next。

                         3、设置项目属性(具体如下),设置完成之后点击 Finish 就可以

      (在新建过程尽量不要动这个窗口<最小化也行>,可能建项目的过程有些慢)
               
如果想省事的直接复制我的代码成功运行,项目名字尽量要跟我的一样 WeChat
         如果你要坚持要自己名字的,那你注意我的代码出现 wechat 时看看需不需要更改

         SDK如果想用低版本的,比如:我想用Android 10,记得在Minimum SDK下更改版本

Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android

        4、以下就是整个项目的全貌,我展开的都是需要经常用的到文件

                         5、创建一个 Android 模拟器 运行项目的时候要使用                     

Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android
一、点击Device Manger 在右上角标题
Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android
 二、点击那个 + 号
Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android
三、选择模拟器,一般我选择的是 Pixel 模拟器(这个看个人习惯)
Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android
四、点击下一步 ,这个一定要选择 UpsideDownCake,最后点击 Finish

这样Android 模拟器就新建好了,这个项目也就新建好了

准备开始构建项目

                1、找到 res/values/themes.xml (后缀 后面 有个night不要选择),然后进行修改,shift+F10 运行一下

<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>

   Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android            Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android                                                                                                

                2、将自己的图标(就是底部导航栏的图标)放到 res/drawable 文件目录下

        (具体路径查询看下方)这些是我在iconmonstr网站下载  下载格式 .PNG

Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android

Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android
查看res/drawable路径
Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android
查看res/drawable路径

                

                3、找到 res/menu/bottom_nav_menu.xml 文件 进行修改

                (这时候运行一下,如果模拟器能显示出来界面,导航栏多了个东西,就差不多可以了,不过导航栏却动不了,这个是正常的,因为还没有设置到它)

<?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>

                4、现在开始设置底部导航栏的跳转, 找到 res/navigation/mobile_navigation.xml  文件修改

<?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>

                 5、找到 MainActivity 进行修改

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)
    }
}

          修改完成!直接运行项目(running)

Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android

恭喜你完成最最简单的微信主界面UI🎉🎉🎉

这似乎有点粗糙,那么接下来继续完善

(也就是把咖啡上别人的拉花,换成自己的拉花,内核没有什么大的改动)
        主要都是 更改名字 为项目后面 操作流畅 打下基础

        1、找到 res/values/string.xml 文件修改

<resources>
    <string name="app_name">WeChat</string>
    <string name="title_WeiChat">WeChat</string>
    <string name="title_Friend">Friend</string>
    <string name="title_Search">Search</string>
    <string name="title_Self">Self</string>
</resources>

        2、修改 res/layout 文件夹下的文件

                一、首先新建一个xml文件在 res/layout 目录下 fragment_self.xml

Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android

Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android

                二、然后编写 fragment_self.xml   

<?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=".ui.home.HomeFragment">

    <TextView
        android:id="@+id/text_self"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:textAlignment="center"
        android:textSize="20sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

        3、修改 ui 文件

Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android

 Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android

Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android

Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android

                一、修改self文件夹下文件名称(主要操作改名)如图

Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android

Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android

Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android

Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android

Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android
这时候运行一下项目看看是否改名成功,项目运行成功接着往下做

        一般情况下这个Rename Variables只有一个选项直接勾选就可以,只不过因为我们是复制UI下同个文件夹,导致它判断出多个情况

        你可以根据这个顺序更改文件名:

                home - > weichat

                dashboard -> friend

                notifiction - > search

                二、同理将ui下的另外三个文件夹都给改了名字

Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android

                三、更改文件中的代码                        

----------------------------------------------------------------------------
friendFragment文件::
----------------------------------------------------------------------------
package com.example.wechat.ui.friend

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.example.wechat.databinding.FragmentFriendBinding

class friendFragment : Fragment() {

    private var _binding: FragmentFriendBinding? = null

    // This property is only valid between onCreateView and
    // onDestroyView.
    private val binding get() = _binding!!

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        val friendViewModel =
            ViewModelProvider(this).get(friendViewModel::class.java)

        _binding = FragmentFriendBinding.inflate(inflater, container, false)
        val root: View = binding.root

        val textView: TextView = binding.textFriend
        friendViewModel.text.observe(viewLifecycleOwner) {
            textView.text = it
        }
        return root
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
}

----------------------------------------------------------------------------
friendViewModel文件::
----------------------------------------------------------------------------
package com.example.wechat.ui.friend

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class friendViewModel : ViewModel() {

    private val _text = MutableLiveData<String>().apply {
        value = "This is Friend Fragment"
    }
    val text: LiveData<String> = _text
}
---------------------------------------------------------------------------
searchFragment文件::
---------------------------------------------------------------------------
package com.example.wechat.ui.search

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.example.wechat.databinding.FragmentSearchBinding

class searchFragment : Fragment() {

    private var _binding: FragmentSearchBinding? = null

    // This property is only valid between onCreateView and
    // onDestroyView.
    private val binding get() = _binding!!

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        val searchViewModel =
            ViewModelProvider(this).get(searchViewModel::class.java)

        _binding = FragmentSearchBinding.inflate(inflater, container, false)
        val root: View = binding.root

        val textView: TextView = binding.textSearch
        searchViewModel.text.observe(viewLifecycleOwner) {
            textView.text = it
        }
        return root
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
}
---------------------------------------------------------------------------
searchViewModel文件::
---------------------------------------------------------------------------
package com.example.wechat.ui.search

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class searchViewModel : ViewModel() {

    private val _text = MutableLiveData<String>().apply {
        value = "This is Search Fragment"
    }
    val text: LiveData<String> = _text
}
---------------------------------------------------------------------------
selfFragment文件::
---------------------------------------------------------------------------
package com.example.wechat.ui.self

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.example.wechat.databinding.FragmentSelfBinding

class selfFragment : Fragment() {

    private var _binding: FragmentSelfBinding? = null

    // This property is only valid between onCreateView and
    // onDestroyView.
    private val binding get() = _binding!!

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        val selfViewModel =
            ViewModelProvider(this).get(selfViewModel::class.java)

        _binding = FragmentSelfBinding.inflate(inflater, container, false)
        val root: View = binding.root

        val textView: TextView = binding.textSelf
        selfViewModel.text.observe(viewLifecycleOwner) {
            textView.text = it
        }
        return root
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
}

---------------------------------------------------------------------------
selfViewModel文件::
---------------------------------------------------------------------------
package com.example.wechat.ui.self

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class selfViewModel : ViewModel() {

    private val _text = MutableLiveData<String>().apply {
        value = "This is Self Fragment"
    }
    val text: LiveData<String> = _text
}

---------------------------------------------------------------------------
wechatFragment文件::
---------------------------------------------------------------------------
package com.example.wechat.ui.wechat

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.example.wechat.databinding.FragmentWechatBinding

class wechatFragment : Fragment() {

    private var _binding: FragmentWechatBinding? = null

    // This property is only valid between onCreateView and
    // onDestroyView.
    private val binding get() = _binding!!

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        val wechatViewModel =
            ViewModelProvider(this).get(wechatViewModel::class.java)

        _binding = FragmentWechatBinding.inflate(inflater, container, false)
        val root: View = binding.root

        val textView: TextView = binding.textWechat
        wechatViewModel.text.observe(viewLifecycleOwner) {
            textView.text = it
        }
        return root
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
}

---------------------------------------------------------------------------
wechathViewModel文件::
---------------------------------------------------------------------------
package com.example.wechat.ui.wechat

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class wechatViewModel : ViewModel() {

    private val _text = MutableLiveData<String>().apply {
        value = "This is Wechat Fragment"
    }
    val text: LiveData<String> = _text
}

        5、更改 res/layout 文件下文件

                一、更改文件名字

Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android
修改前

Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android

  

        请根据这个顺序更改文件名(不要到后面会混乱的):

                home - > wechat

                dashboard -> friend

                notifiction - > search

                二、更改文件中的代码

fragment_wechat.xml
      
        android:id="@+id/text_home"

改成-------

        android:id="@+id/text_wechat"

-------------------------------------------------------
fragment_friend.xml
      
        android:id="@+id/text_dashboard"

改成-------

        android:id="@+id/text_friend"

-------------------------------------------------------

fragment_search.xml
      
        android:id="@+id/text_notifications"

改成-------

        android:id="@+id/text_friend"

        5、找到 res/navigation/moobile_navigation.xml 文件修改

<?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.wechat.wechatFragment"
        android:label="@string/title_WeiChat"
        tools:layout="@layout/fragment_wechat" />

    <fragment
        android:id="@+id/navigation_Friend"
        android:name="com.example.wechat.ui.search.searchFragment"
        android:label="@string/title_Friend"
        tools:layout="@layout/fragment_friend" />

    <fragment
        android:id="@+id/navigation_Search"
        android:name="com.example.wechat.ui.friend.friendFragment"
        android:label="@string/title_Search"
        tools:layout="@layout/fragment_search" />

    <fragment
        android:id="@+id/navigation_Self"
        android:name="com.example.wechat.ui.self.selfFragment"
        android:label="@string/title_Self"
        tools:layout="@layout/fragment_self" />
</navigation>

Android Studio Kotlin 简单实现微信主界面UI,android studio,kotlin,android

恭喜你完成最简单的微信主界面UI🎉🎉🎉

                                                            

  文章来源地址https://www.toymoban.com/news/detail-853371.html

到了这里,关于Android Studio Kotlin 简单实现微信主界面UI的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Android Studio制作简单登录界面

    应用线性布局设计登录界面,要求点击输入学号时弹出数字键盘界面,点击输入密码时弹出字母键盘,出现的文字、数字、尺寸等全部在values文件夹下相应.xml文件中设置好,使用时直接引用。当用户名或密码为空,显示一个提示信息“用户名与密码不能为空!”,当用户名和

    2024年04月15日
    浏览(38)
  • Android studio编写一个简单的登录界面

    1首先先创建一个空的activity项目,接着设置自己的项目名称,勾选上lacuncher 创建成功后点开 manifests 把刚刚创建的文件名下面的 intent-filter 这一行全部删除 然后点开res,复制一张图片,右键drawable点击粘贴,这里放的是图片资源,用于放置登录头像 然后点开layout文件,开始编

    2024年04月15日
    浏览(29)
  • 在 Android Studio 中创建一个简单的 QQ 登录界面

            打开 Android Studio,选择 \\\"Start a new Android Studio project\\\",然后填写应用程序名称、包名和保存路径等信息。接下来,选择 \\\"Phone and Tablet\\\" 作为您的设备类型,然后选择 \\\"Empty Activity\\\" 作为您的 Activity 模板。         在 Android Studio 中,布局文件用于指定应用程序的用

    2024年02月07日
    浏览(36)
  • 移动应用开发之路 05 Android Studio 简单登录界面制作

    学校开了一门移动应用开发课程,我一开始兴趣盎然,但是看到使用的环境是 Java 8 的时候心就凉了一半,在询问老师的意见之后决定使用现在比较常用的Android Studio完成学习,特此记录自学之路。 这篇是一个总结性质的文章,主要为了熟练运用之前讲过的几个UI控件。小项目

    2024年02月08日
    浏览(47)
  • UI界面开发- android studio搭建类微信界面

    目录 1.实验目的 2.开发过程 一、界面框架设计思路 Ⅰ:顶部标题区域top.xml Ⅰ:底部功能选择区域botten.xml Ⅲ:中间显示区域  ①:创建不同的Fragment.java及layout ②:activity_main.xml整体框架搭建​编辑 ③:实现Fragment的隐藏和显示         1.在主函数中定义控件         2.定

    2024年02月06日
    浏览(36)
  • Android Studio 制作微信界面 下

         上一篇文章的链接: Android Studio 制作微信界面 上_nazonomaster的博客-CSDN博客 https://blog.csdn.net/nazonomaster/article/details/124456716                 首先是WeixinFragment.java                 在包内创建一个名为fragment的文件夹,在该文件夹中创建新的Java类并命名为

    2024年02月09日
    浏览(35)
  • Android Studio之搭建微信界面

    目录 目录 一、功能需求 二 、页面布局 一,将所需图片导入 二, 顶部top.xml设计 三,底部buttom1.xml设计 四,中间页面设计  五, 将底部中部以及中部进行整合 三、页面跳转控制  一,BlankFragment文件 二,MainActivity文件  四、在任一tab页中实现列表效果  一, 添加的Recyc

    2024年02月03日
    浏览(29)
  • Android studio安卓跳转界面(导航栏返回箭头)(十分简单)

    安卓界面跳转(只是实现效果,不讨论其他影响,望周知)   Android studio页面跳转导航栏返回箭头,是非常基础的操作,不讲解,不深究,只是实现效果 导航栏返回箭头,效果如下:   在AndroidManifest.xml下的application中添加     代码如下: 全局代码: 顺便再讲一个显示跳转

    2024年02月06日
    浏览(35)
  • Android Studio汉化教程/编辑器界面转换为中文(简单步骤)

    此方法很简单,只需要下载插件引入即可 前往下方链接,然后点击GET,Download对应版本(建议不要下载太新版本,不然会不兼容,可以下载Android Studio适应的版本) https://plugins.jetbrains.com/plugin/13710-chinese-simplified-language-pack---- 这里有适用的版本 然后解压刚刚下载的zip 打开设置

    2024年02月12日
    浏览(36)
  • Android Studio 制作微信,登入界面,输入密码界面,跳转手机登录界面,以及聊天界面

    2.打开Android Studio。 3.选择 \\\"Create New Project\\\"。 4.在 \\\"Create New Project\\\" 对话框中,输入项目名称、选择存储位置等信息。 5.选择最低支持的Android版本,并选择一个适合的活动模板(例如,Empty Activity)。 6.点击 \\\"Finish\\\" 创建新的Android项目。 8.打开 \\\"activity_main.xml\\\" 文件,该文件用于定

    2024年02月07日
    浏览(34)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包