实战演练—记账本App(一)

实战演练—记账本App(一),第1张

概述在学习了Androidstudio的基本使用方法和了解了APP的基本结构后,准备开始开发一个家庭记账本app,就算是对假期学习的一个小小的总结。由于刚接触app方面的知识,所以目前只能开发出一个简单的app项目。思路构想:用户打开app进入主页,会给用户提供两个选择按钮,如果选择“今天花钱了”,a

在学习了AndroID studio的基本使用方法和了解了APP的基本结构后,准备开始开发一个家庭记账本app,就算是对假期学习的一个小小的总结。由于刚接触app方面的知识,所以目前只能开发出一个简单的app项目。

思路构想:用户打开app进入主页 ,会给用户提供两个选择按钮,如果选择“今天花钱了” ,app首先会显示当前所有的消费记录(以商品、购买日期、价格形式显示)。在此页面,用户点击添加按钮后会d出一个文本框,用户可以依次输入购买的商品名,价格,选择购买日期,来添加消费记录。当用户选择“OK”,则确定添加,同时会回到主页,并刷新出用户所添加的信息。总的思路构想就是这些了。目前只完成这么多功能,至于“今天赚钱了”功能,后期学到更多知识后会添加。

下面是app的功能流程图:

 

 

 今天完成了页面的跳转,代码如下:

1、在layout下创建一个skip_layout.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-@R_404_6843@"
xmlns:tools="http://schemas.androID.com/tools"
androID:layout_wIDth="match_parent"
androID:layout_height="match_parent"
tools:context=".SkipActivity">

<TextVIEw
androID:layout_wIDth="wrap_content"
androID:layout_height="wrap_content"
androID:text="跳转的界面!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintleft_toleftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constrainttop_totopOf="parent" />

</androIDx.constraintlayout.Widget.ConstraintLayout>

2、编写SkipActivity.java文件,修改启动的界面为skip_layout

package com.example.togglepages;import androID.os.Bundle;import androIDx.appcompat.app.AppCompatActivity;public class SkipActivity extends AppCompatActivity {    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.skip_layout);    }}

3、编辑好SkipActivity.java文件后,要在AndroIDMainifest.xml里面注册SkipActivity,注册的代码如下

<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"    package="com.example.togglepages">    <application        androID:allowBackup="true"        androID:icon="@mipmap/ic_launcher"        androID:label="@string/app_name"        androID:roundIcon="@mipmap/ic_launcher_round"        androID:supportsRtl="true"        androID:theme="@style/Apptheme">        <activity androID:name=".MainActivity">            <intent-filter>                <action androID:name="androID.intent.action.MAIN" />                <category androID:name="androID.intent.category.LAUNCHER" />            </intent-filter>        </activity>        <activity androID:name=".SkipActivity">        </activity>    </application></manifest>

4、在activity_main.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-@R_404_6843@"    xmlns:tools="http://schemas.androID.com/tools"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:background="@mipmap/b"    tools:context=".MainActivity">    <TextVIEw        androID:ID="@+ID/textVIEw"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_margintop="100dp"        androID:layout_marginBottom="165dp"        androID:textSize="30dp"        androID:textStyle="bold"        androID:text="MM记账本"        androID:textcolor="#53c3eb"        app:layout_constraintBottom_totopOf="@+ID/btn"        app:layout_constraintHorizontal_bias="0.473"        app:layout_constraintleft_toleftOf="parent"        app:layout_constraintRight_toRightOf="parent"        app:layout_constrainttop_totopOf="parent"        app:layout_constraintVertical_bias="0.084" />    <button        androID:ID="@+ID/btn"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_margintop="40dp"        androID:layout_marginBottom="33dp"        androID:text="今天花钱了"        androID:background="#1c97f5"        app:layout_constraintBottom_totopOf="@+ID/button2"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constraintStart_toStartOf="parent"        app:layout_constrainttop_toBottomOf="@+ID/textVIEw" />    <button        androID:ID="@+ID/button2"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_marginBottom="110dp"        androID:text="今天赚钱了"        androID:background="#1c97f5"        app:layout_constraintBottom_toBottomOf="parent"        app:layout_constraintStart_toStartOf="@+ID/btn"        app:layout_constrainttop_toBottomOf="@+ID/btn" /></androIDx.constraintlayout.Widget.ConstraintLayout>

5、添加了按钮后,修改MainActivity.java文件,在onCreate中获取刚刚在界面文件中添加的按钮,并且实现点击事件监听。并在事件触发处理函数中添加界面跳转的代码,实现界面跳转使用了Intent,具体的代码如下

package com.example.togglepages;import androIDx.appcompat.app.AppCompatActivity;import androID.content.Intent;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.Widget.button;public class MainActivity extends AppCompatActivity {    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        button btn=findVIEwByID(R.ID.btn);        btn.setonClickListener(new VIEw.OnClickListener(){            @OverrIDe            public voID onClick(VIEw v){                Intent it=new Intent();                it.setClass(MainActivity.this,SkipActivity.class);                        MainActivity.this.startActivity(it);            }        });    }}

效果图:

 

 

 

 

总结

以上是内存溢出为你收集整理的实战演练—记账本App(一)全部内容,希望文章能够帮你解决实战演练—记账本App(一)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1065878.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存