终于,Android作业弄完了,最后一个,备忘录教学。

相关安卓教学内容:

首先第一步,还是老样子,创建一个NoteActivity。

image.png

第二步,打开activity_note.xml,开始布局,话不多说了,关于这一块的内容我在登录,注册当中已经教学的很详细了,直接上代码吧,反正我码再多字估计你们也不看....

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=".NoteActivity"

android:background="@drawable/notebg">

android:id="@+id/textView3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:layout_marginTop="10dp"

android:text="备忘录"

android:textSize="30dp"/>

android:id="@+id/editText3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:ems="10"

android:minLines="17"

android:inputType="textMultiLine"

android:hint="点击此处输入文字"

android:background="@null"

android:layout_marginLeft="20dp"

android:layout_marginRight="20dp"

android:layout_alignParentStart="true"

android:layout_above="@+id/button4"

android:layout_alignParentEnd="true"

android:layout_below="@+id/textView3"

android:gravity="left|top"

android:textSize="20dp"/>

android:id="@+id/button4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="保存"

android:layout_alignParentBottom="true"

android:layout_alignStart="@+id/editText3" />

android:id="@+id/button5"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="重置"

android:layout_alignParentBottom="true"

android:layout_alignEnd="@+id/editText3" />

android:id="@+id/textView4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignBottom="@+id/textView3"

android:layout_alignEnd="@+id/editText3"

android:text="0个字" />

效果如下:怎么样,看上去还不错吧?

image.png

接下来打开NoteActivity,直接上代码,不想码注释了,码了也没人看,反正你们最喜欢的就是复制粘贴代码

package com.wxy.homework;

import android.content.Context;

import android.content.pm.ActivityInfo;

import android.os.Bundle;

import android.text.Editable;

import android.text.TextWatcher;

import android.view.KeyEvent;

import android.view.View;

import android.view.WindowManager;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

import android.widget.Toast;

import androidx.appcompat.app.ActionBar;

import androidx.appcompat.app.AppCompatActivity;

import java.io.FileInputStream;

import java.io.FileOutputStream;

public class NoteActivity extends AppCompatActivity {

private EditText inputInfo;

private Button save;

private Button reset;

private TextView count;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_note);

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

setFullScreen();

hideBar();

inputInfo = (EditText) findViewById(R.id.editText3);

save = (Button) findViewById(R.id.button4);

reset = (Button) findViewById(R.id.button5);

count = (TextView)findViewById(R.id.textView4);

inputInfo.addTextChangedListener(new TextWatcher() {

@Override

public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@Override

public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@Override

public void afterTextChanged(Editable editable) {

count.setText(inputInfo.getText().length()+"个字");

}

});

onload();

inputInfo.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

inputInfo.setCursorVisible(true);

}

});

save.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

FileOutputStream fos = null;

try{

fos = openFileOutput("txt", Context.MODE_PRIVATE);

String text = inputInfo.getText().toString();

fos.write(text.getBytes());

}catch (Exception e){

e.printStackTrace();

}finally {

try{

if(fos!=null){

fos.flush();

Toast.makeText(NoteActivity.this,"保存成功!",Toast.LENGTH_SHORT).show();

fos.close();

}

}catch(Exception e){

e.printStackTrace();

}

}

}

});

reset.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

FileOutputStream fos = null;

inputInfo.setText("");

try{

fos = openFileOutput("txt", Context.MODE_PRIVATE);

String text = "";

fos.write(text.getBytes());

}catch (Exception e){

e.printStackTrace();

}finally {

try{

if(fos!=null){

fos.flush();

Toast.makeText(NoteActivity.this,"清空成功!",Toast.LENGTH_SHORT).show();

fos.close();

}

}catch(Exception e){

e.printStackTrace();

}

}

}

});

}

public void onload(){

FileInputStream fis = null;

try{

fis = openFileInput("txt");

if(fis.available()==0){

return;

}else{

byte[] con = new byte[fis.available()];

while(fis.read(con)!=-1){

}

inputInfo.setText(new String(con));

inputInfo.setSelection(inputInfo.getText().length());

inputInfo.setCursorVisible(false);

}

}catch(Exception e){

e.printStackTrace();

}

}

long time;

public boolean onKeyDown(int keyCode, KeyEvent event){

if(keyCode==KeyEvent.KEYCODE_BACK&&event.getAction()==KeyEvent.ACTION_DOWN){

if(System.currentTimeMillis()-time>2000){

Toast.makeText(NoteActivity.this,"再次点击返回键,程序退出",Toast.LENGTH_SHORT).show();

time = System.currentTimeMillis();

}else{

NoteActivity.this.finish();

}

return true;

}

return super.onKeyDown(keyCode,event);

}

private void hideBar(){

ActionBar actionBar = getSupportActionBar();

if(actionBar!=null){

actionBar.hide();

}

}

private void setFullScreen(){

this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

WindowManager.LayoutParams.FLAG_FULLSCREEN);

}

}

然后,老师作业要求是,登录之后,直接跳转到备忘录,所以我们要调整启动顺序。打开LoginActivity,

调整启动顺序

image.png

好了,激动人心的时候又到了,直接开始测试

我们输入之前注册的用户名称和密码进行登录

image.png

发现登录成功,完美跳转到备忘录界面

image.png

我们输入任意字符,点击保存,发现保存成功,且下次登录时,直接显示保存的字符

image.png

我们点击右下角的重置,发现备忘录内容全部清空,完美运行

image.png

好了我亲爱的同学们,安卓作业搞定了。

欢迎关注我,我将不定期更新教学博客和技术贴。

android备忘录教学_Android Studio-备忘录功能实现相关推荐

  1. android备忘录教学_Android Studio实战 - 备忘录实验

    [导读]到目前为止,你已经熟悉了关于创建新项目.编程和重构的基础知识,是时候创建一款 Android应用(也称为App) 了. 到目前为止,你已经熟悉了关于创建新项目.编程和重构的基础知识,是时候创建 ...

  2. android备忘录教学_Android学习备忘录

    看的框架层相关的概念容易忘记,写个备忘录把理解的重点和遇到的疑惑记下. Context:用Android最早接触到的一个类,使用非常非常广泛,在各个地方都要用到,像Toast.Dialog.new T ...

  3. android备忘录教学_android基础备忘录(一)

    1.drawable-(hdpi,mdpi,ldpi)的区别 dpi是"dot per inch"的缩写,每英寸像素数. 四种密度分类: ldpi (low), mdpi (med ...

  4. android备忘录教学_android备忘录教学_Android Studio-备忘录功能实现

    终于,Android作业弄完了,最后一个,备忘录教学. 相关安卓教学内容: 首先第一步,还是老样子,创建一个NoteActivity. image.png 第二步,打开activity_note.xm ...

  5. android tag 快捷_Android Studio快捷键生成TAG、Log.x日志输出介绍

    生成TAG logt+Tab键: private static final String TAG = "Extract"; 生成Log.d() logd+Tab键: Log.d(T ...

  6. android shn1 获取_Android Studio获取开发版SHA1值和发布版SHA1值的史上最详细方法

    前言:使用百度地图时需要秘钥,申请秘钥时需要SHA1值,所以今天就总结一下怎么获取这个值. 正常情况下: 一.获取开发版SHA1: 在此我直接用AndroidStudio提供的命令控制台了,毕竟做An ...

  7. android tag 快捷_Android Studio快捷键使用

    logt 生成 TAG标签 private static final String TAG = "MainActivity"; logm 打印方法具体日志 Log.d(TAG, & ...

  8. android java显示_Android Studio没有显示java类源代码

    我搜索了这个问题并尝试了所提出的解决方案但没有成功.我有一个项目,当我去查看源文件时,让我说Fragment它让我到 java类就好了. 现在当我去File – >新项目并完成所有相同的设置程序 ...

  9. Android设计模式详解之备忘录模式

    前言 备忘录模式是一种行为模式,该模式用于保存对象当前状态,并且在之后可以再次恢复到此状态: 定义:在不破坏封闭的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态,这样,以后就可以将该对象恢 ...

最新文章

  1. nginx+php-fpm 的配置下,php的错误日志
  2. 实现锁死的有滚动条的div的表格(datagird)
  3. 推荐系统炼丹笔记:RecSys2020-SSE-PT解锁序列数据挖掘新姿势
  4. debian安装搜狗
  5. html 甘特图_Rplotly|交互式甘特图(Gantt chart)项目管理/学习计划
  6. 在Windows下编译ffmpeg完全手册
  7. arduinojson 转 string_安德胜工作室发来本周五嗨唱转起来第二季首秀的嘉宾剧透...
  8. xy坐标正负方向_【笛卡尔坐标系】
  9. poj1113/hdu1348(凸包。。。两个网站上的输入输出有点出入)
  10. 微课|中学生可以这样学Python(例5.4):计算决赛现场选手得分
  11. html dom手机版,HTML DOM - 元素
  12. python怎么开始_Python自己学习怎么开始?
  13. PouchContainer 开源版本及内部版本一致性实践
  14. 9.4SAS软件入门
  15. 脚本重启电信天翼网关
  16. 如何管理计算机回收站,回收站功能多多 教你如何玩转回收站
  17. AngularJs:Directive指令用法
  18. Python图算法之狄克斯特拉算法
  19. android9 0正式版,安卓9.0系统正式版|Android Pie 9.0 正式版 - 天天游戏吧
  20. 【basepro】常用util

热门文章

  1. web3D 车型展示
  2. 02.Linux的基础命令
  3. node.js的第三方模块 nodemon、nrm、Gulp、Gulp插件
  4. PROFINET 网络拓扑图是如何生成的?
  5. 瑞芯微RK3399助力AI场景应用
  6. SEO做外链Outreach邮件回复低,怎么办?
  7. 2012年经济与股市战略
  8. SQL: 视图和表的区别
  9. c++贪吃蛇小项目学习使用设计模式:单例模式,策略模式
  10. 会计初级可以自己报名吗_初级会计考试可以自学吗?我刚完成报名