文章目录
- 一、引言
- 二、设计
- 1、通讯录
- (1)效果
- (2)思路
- (3)实现
 
- 2、记事本
- (1)效果
- (2)思路
- (3)实现
 
 
- 三、附件
- 1、计算器UI界面设计
- 2、源代码
 
 
一、引言
- 描述:通讯录、记事本、计算器这已经很常见了,基本每台手机都有。那么还有学习设计的必要吗?当然,初学者学习一套技术时,必然要先学会复刻,然后再创新。复刻是技术提升的过程,创新是技术深度的证明。没有生而知之者,更没有抄袭之说,只能说我们是站在巨人的肩膀上观澜世界。
- 知识点:
 1、SQLite数据库的使用
 2、按钮样式设计
 3、点击、长按事件的使用
 4、全局样式的修改
- 难度:初级
二、设计
1、通讯录
(1)效果

(2)思路
对于数据的管理肯定就是最最基本的增删改查,这是毋庸置疑的。初学者在五天内能够将这些操作做到滚瓜烂熟就已经非常不错了。剩下的就交个Intent组件进行通讯的跳转和连接。
(3)实现
因为效果简单,我就不封装数据库操作方法,只贴主要代码,源码请看附件。
- Insert
db = myhelper.getWritableDatabase();
values = new ContentValues();
values.put("name",name);
values.put("phone",phone);
db.insert("listphone",null,values);
Toast.makeText(this,"信息添加成功",Toast.LENGTH_SHORT).show();
db.close();
- Update
db = myhelper.getReadableDatabase();
values = new ContentValues();
if (TextUtils.isEmpty(names.getText())){
    Toast.makeText(this,"所需要修改的姓名不能为空!!",Toast.LENGTH_SHORT).show();
    break;
} else if (update_id == null){
    values.put("phone" , phone = phones.getText().toString());
    db.update("listphone",values,"name=?",new String[]{names.getText().toString()});
    Toast.makeText(this,"信息修改成功!!",Toast.LENGTH_SHORT).show();
} else {
    values.put("name" , phone = names.getText().toString());
    values.put("phone" , phone = phones.getText().toString());
    db.update("listphone",values,"_id=?",new String[]{update_id});
    Toast.makeText(this,"信息修改成功!!",Toast.LENGTH_SHORT).show();
}
db.close();
- Delete
db = myhelper.getReadableDatabase();
if (TextUtils.isEmpty(names.getText())){
    Toast.makeText(this,"请输入需要删除的联系人!!",Toast.LENGTH_SHORT).show();
    break;
}
db.delete("listphone", "name=?",new String[]{names.getText().toString()});
Toast.makeText(this,"信息删除成功!!",Toast.LENGTH_SHORT).show();
db.close();
- Query
db = myhelper.getReadableDatabase();
Cursor cursor = db.query("listphone",null,null,null,null,null,null);
cursor.moveToFirst();
data = new ArrayList<>();
next = new ArrayList<>();
ids = new ArrayList<>();
if (cursor.getCount() == 0){
    Toast.makeText(this,"通讯录为空!!",Toast.LENGTH_SHORT).show();
} else {
    ids.add(cursor.getString(0));
    data.add(cursor.getString(1));
    next.add(cursor.getString(2));
} while (cursor.moveToNext()){
    ids.add(cursor.getString(0));
    data.add(cursor.getString(1));
    next.add(cursor.getString(2));
}
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,R.layout.phine_list,R.id.li,data);
ArrayAdapter<String> adapter1 = new ArrayAdapter<>(this,R.layout.phine_list,R.id.li,next);
list.setAdapter(adapter);
list1.setAdapter(adapter1);
cursor.close();
db.close();]
2、记事本
(1)效果

(2)思路
数据操作也是增删改查,但是更多的则是一些需求的完成。
比如:
1、字体加粗、字体放大/放小、斜体等基本字体操作
2、删除,总不能点进去删,需要局外遍历删除,是长按还是滑动?
3、搜索,模糊搜索,搜索的字段有哪些?
(3)实现
数据库操作在通讯录里已经写过同样的操作,这里就不重复了,就写点其他功能。
- 长按
AlertDialog dialog;
AlertDialog.Builder builder = new AlertDialog.Builder( NotepadActivity.this)
        .setMessage("是否删除此事件?")
        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Notepbook notepadBean = list.get(position);
                if(mSQLiteHelper.deleteData(notepadBean.getId())){
                    list.remove(position);
                    adapter.notifyDataSetChanged();
                    Toast.makeText(NotepadActivity.this,"删除成功",
                            Toast.LENGTH_SHORT).show();
                }
            }
        })
        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
dialog =  builder.create();
dialog.show();
- 字体样式
case R.id.bin_bold:  // 加粗
    content.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
    break;
case R.id.bin_italic:  // 斜体
    content.setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC));
    break;
case R.id.bin_a:  // 变小
    fend -= 5;
    content.setTextSize(fend);
    break;
case R.id.bin_A:  // 变大
    fend += 5;
    content.setTextSize(fend);
    break;
三、附件
1、计算器UI界面设计
计算器就当是给初学者练习的项目
- 效果
  
- 代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#666"
    tools:context=".MainActivity">
    <EditText
        android:id="@+id/main_01"
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:textColor="#fff"
        android:gravity="center_vertical|right"
        android:background="#F0F0F0"/>
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/main_01"
        android:layout_marginTop="20dp">
        <Button
            android:id="@+id/text_ac"
            style="@style/textStyle1"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:background="@drawable/shape_w"
            android:text="AC"
            android:textColor="#000"/>
        <Button
            android:id="@+id/user_1"
            style="@style/textStyle1"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_toRightOf="@id/text_ac"
            android:background="@drawable/shape_w"
            android:text="±"
            android:textColor="#000" />
        <Button
            android:id="@+id/user_bai"
            style="@style/textStyle1"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_toRightOf="@id/user_1"
            android:background="@drawable/shape_w"
            android:text="%"
            android:textColor="#000" />
        <Button
            android:id="@+id/text_chu"
            style="@style/textStyle2"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_toRightOf="@id/user_bai"
            android:background="@drawable/shape_o"
            android:text="÷" />
        <Button
            android:id="@+id/text_01"
            style="@style/textStyle1"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_below="@id/text_ac"
            android:background="@drawable/shape_b"
            android:text="1" />
        <Button
            android:id="@+id/text_02"
            style="@style/textStyle1"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_below="@id/text_ac"
            android:layout_toRightOf="@id/text_01"
            android:background="@drawable/shape_b"
            android:text="2" />
        <Button
            android:id="@+id/text_03"
            style="@style/textStyle1"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_below="@id/text_ac"
            android:layout_toRightOf="@id/text_02"
            android:background="@drawable/shape_b"
            android:text="3" />
        <Button
            android:id="@+id/text_jia"
            style="@style/textStyle2"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_below="@id/text_chu"
            android:layout_toRightOf="@id/user_bai"
            android:background="@drawable/shape_o"
            android:text="+" />
        <Button
            android:id="@+id/text_04"
            style="@style/textStyle1"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_below="@id/text_01"
            android:background="@drawable/shape_b"
            android:text="4" />
        <Button
            android:id="@+id/text_05"
            style="@style/textStyle1"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_below="@id/text_01"
            android:layout_toRightOf="@id/text_04"
            android:background="@drawable/shape_b"
            android:text="5" />
        <Button
            android:id="@+id/text_06"
            style="@style/textStyle1"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_below="@id/text_01"
            android:layout_toRightOf="@id/text_05"
            android:background="@drawable/shape_b"
            android:text="6" />
        <Button
            android:id="@+id/text_jiang"
            style="@style/textStyle2"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_below="@id/text_jia"
            android:layout_toRightOf="@id/user_bai"
            android:background="@drawable/shape_o"
            android:text="-" />
        <Button
            android:id="@+id/text_07"
            style="@style/textStyle1"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_below="@id/text_04"
            android:background="@drawable/shape_b"
            android:text="7" />
        <Button
            android:id="@+id/text_08"
            style="@style/textStyle1"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_below="@id/text_04"
            android:layout_toRightOf="@id/text_07"
            android:background="@drawable/shape_b"
            android:text="8" />
        <Button
            android:id="@+id/text_09"
            style="@style/textStyle1"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_below="@id/text_04"
            android:layout_toRightOf="@id/text_08"
            android:background="@drawable/shape_b"
            android:text="9" />
        <Button
            android:id="@+id/text_cheng"
            style="@style/textStyle2"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_below="@id/text_jiang"
            android:layout_toRightOf="@id/user_bai"
            android:background="@drawable/shape_o"
            android:text="×" />
        <Button
            android:id="@+id/text_00"
            style="@style/textStyle1"
            android:layout_width="160dp"
            android:layout_height="80dp"
            android:layout_below="@id/text_07"
            android:background="@drawable/shape"
            android:text="0" />
        <Button
            android:id="@+id/text_dian"
            style="@style/textStyle1"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_below="@id/text_07"
            android:layout_toRightOf="@id/text_00"
            android:background="@drawable/shape_b"
            android:text="." />
        <Button
            android:id="@+id/text_deng"
            style="@style/textStyle2"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_below="@id/text_cheng"
            android:layout_toRightOf="@id/user_bai"
            android:background="@drawable/shape_o"
            android:text="=" />
    </RelativeLayout>
</RelativeLayout>
2、源代码
gitee下载地址:
1、通讯录:https://gitee.com/xu-pq/android-demo/tree/master/Android_Sqlite
2、记事本:https://gitee.com/xu-pq/android-demo/tree/master/Android_Notebook2
3、计算器:https://gitee.com/xu-pq/android-demo/tree/master/diyic



















