Kotlin开发安卓APP笔记实战-写个简易记事本(需求分析)

Kotlin不止之前笔记里学的这些基础,不过不看了,还是实战吧,遇到问题再去解决。
创建工程环境啥的之前都讲过就不讲了,阅读此笔记需要一些安卓开发的经验和知识,不懂的可以在猫客论坛评论区提问,或者我的csdn博客地址评论,不知道有没有转载,欢迎转载,注明出处就好。因为白天需要上班,可能更新得会慢一点。

分析记事本功能以及画草图

无论做什么事,脑袋里面一定先要有对这件事情有个大致的思路,该怎样去做,胸有成竹,这样才能画出好的竹子。做软件也一样,你可以把你自己做的事情当成在搞艺术。。。(不吹了,吹起牛来,我自己都害怕0.0)
其实记事本很简单,只需要创建两个页面,一个页面用列表或者九宫控件(RecyclerView/ListView/GridView)显示你创建的item,然后一个页面编辑内容就行了。数据存储使用sqlite,更灵活方便。

设计sqlite表

对于sqlite语法不太了解可以先看看菜鸟教程
设定表名为note

字段数据类型说明
IDINT自增主键
createtimeTIMESTAMP记录创建时间
chagetimeTIMESTAMP记录上一次修改时间
titleCHAR(255)标题
contentTEXT内容(使用TEXT最大可以存储2^31-1个字符,足够我们的记事本使用了)

所以创建表格的sql语句为:

create table note(ID INT PRIMARY KEY NOT NULL,createtime TIMESTAMP NOT NULL,chagetime TIMESTAMP,title CHAR(255) NOT NULL,content TEXT NOT NULL);
画草图

windows自带画图工具用来做个草图还是很好的,做不到很精美的效果,但是你可以快速做出大致的草图,所以我很喜欢用这个工具。win+R输入mspaint命令快速打开画图工具
这里写图片描述

分析界面

界面1
这里是列表显示笔记数据,所以表格控件GridView不适合,选择ListView或者RecyclerView,本笔记选择RecylerView。Item的布局可以选择垂直线性布局,为Item绑定长按事件,作为删除笔记的功能。右下角的“+”按钮作为新增按钮,使用Floating ActionButton。
界面2
这个界面就简单了,上面是一个包含返回按钮和保存按钮的toolbar,不会toolbar也可以使用一个layout实现功能,本笔记将采用toolbar。下面就是一个充满界面的EditText

撸界面

分析完需求,就开始动手吧,先写功能或者先写UI都可以。
引入design库

compile 'com.android.support:design:+'
界面1

这里写图片描述

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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="cn.bestmk.note.MainActivity">
    <!-- 标题栏 -->
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:title="@string/app_name"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>
    <!--笔记列表-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>
    <!--右下角悬浮按钮-->
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@android:drawable/ic_input_add" />

</android.support.design.widget.CoordinatorLayout>
列表Item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp"
    android:orientation="vertical">

    <TextView
        android:id="@+id/tv_title"
        android:textSize="18sp"
        android:textColor="#000000"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="新建笔记" />

    <TextView
        android:id="@+id/tv_createtime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#3F48CC"
        android:textSize="11sp"
        android:text="创建时间:2017-12-26 12:00:00" />
    <TextView
        android:id="@+id/tv_chagetime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#3F48CC"
        android:textSize="11sp"
        android:text="修改时间:2017-12-26 12:00:00" />
</LinearLayout>
界面2
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context="cn.bestmk.note.EditActivity">
<!-- 标题栏 -->

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:icon="@mipmap/back"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        app:title="新建笔记1" />

</android.support.design.widget.AppBarLayout>

<EditText
    android:id="@+id/editText"
    android:gravity="start"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</LinearLayout>

这里写图片描述
还缺一个保存的按钮,由于使用了toolbar,这个按钮需要写到菜单里面
创建res/menu/menu.xml

<menu 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" tools:context=".MainActivity">
    <item android:id="@+id/action_search"
        android:title="Search"
        android:icon="@mipmap/save"
        app:showAsAction="ifRoom"/>
</menu>

接下来在Activity中重写onCreateOptionsMenu方法来给Toolbar控件设置具体菜单条目

package cn.bestmk.note

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast
import android.widget.Toolbar
import kotlinx.android.synthetic.main.activity_edit.*

class EditActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_edit)

        setSupportActionBar(toolbar)//为当前的Activity设置标题栏

        //为save按钮绑定事件
        toolbar.setOnMenuItemClickListener{
            Toast.makeText(this@EditActivity,"save",Toast.LENGTH_LONG).show()
            false
        }

    }
    // 为toolbar创建Menu
    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        getMenuInflater().inflate(R.menu.menu, menu);
        return true;
    }
}

至此页面算是写完了

  • 7
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
为了满足广大Android开发爱好者与从业者的学习需求,我们精心整理并上传了一份全面而实用的Android项目资源包。这份资源包内容丰富,涵盖了从基础知识到实战应用的全方位内容,旨在为开发者们提供一个便捷、高效的学习平台。 一、文件手册 资源包中的文件手册部分,详细记录了Android开发的核心知识点和常用技术。无论是初学者还是有一定经验的开发者,都能从中找到所需的学习资料。手册采用了简洁明了的排版方式,使得查阅更加方便快捷。同时,手册内容深入浅出,既适合新手入门,也能为老手提供有价值的参考。 二、项目实战与练习 为了让学习者能够将理论知识与实践相结合,我们特别准备了项目实战与练习部分。这部分内容包含了多个精心设计的Android项目案例,从需求分析、设计思路到实现过程,都有详细的讲解和代码示例。学习者可以通过实际操作,深入了解Android开发的整个流程,提升自己的实战能力。 此外,我们还提供了一系列练习题,旨在巩固所学知识,检验学习成果。这些练习题既有基础题,也有难度较高的挑战题,适合不同层次的学习者进行练习。 三、Android开发工具集 在Android开发过程中,选择合适的工具能够大大提高开发效率。因此,我们整理了常用的Android开发工具集,包括开发工具、测试工具、性能优化工具等。这些工具都是经过我们精心筛选和测试的,能够帮助开发者们更加高效地进行Android开发工作。 总的来说,这份Android项目资源包是一份不可多得的学习资料,无论你是初学者还是有一定经验的开发者,都能从中受益匪浅。我们希望通过这份资源包,为广大Android开发爱好者与从业者提供一个更加便捷、高效的学习平台,共同推动Android开发领域的发展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值