[안드로이드 스튜디오 APK] 메모장 Memo 오픈 소스







아래 영상은 밑에 보이는 소스를 응용해서 추가적인 기능을 넣어서 영상을 찍은 것입니다.


다음은 기본 메모장 소스입니다.

activity_main.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?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:id="@+id/activity_main">
 
    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="top"
        android:hint="메모 할 내용을 입력하세요." />
 
</LinearLayout>
cs

 drawable을 우클릭하여 아래와 같이 Vector Asset을 눌러줍니다.
그리고 아이콘 버튼을 눌러서 검색창에 setting이라고 누르면 해당 이미지가 나옵니다.

아래 이미지도 추가해주시면 끝.


해당 경로에 파일을 만들어주세요



menu/activity_menu.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
 
    <item
        android:id="@+id/save"
        android:icon="@drawable/ic_save_black_24dp"
        app:showAsAction="always"
        android:title="저장" />
 
    <item
        android:id="@+id/share"
        android:title="공유"
        android:icon="@drawable/ic_share_black_24dp"
        app:showAsAction="always"/>
 
    <item
        android:id="@+id/option"
        android:title="설정"
        android:icon="@drawable/ic_settings_black_24dp"
        app:showAsAction="always|withText"/>
 
</menu>
cs


MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;
 
public class MainActivity extends AppCompatActivity {
    EditText editText;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        editText = (EditText) findViewById(R.id.editText);
        SharedPreferences sharedPreferences = getSharedPreferences("first", MODE_PRIVATE);
        String savedString = sharedPreferences.getString("sampleString""");
        editText.setText(savedString);
    }
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_menu, menu);
        return true;
    }
 
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        switch (id) {
            case R.id.save:
 
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setTitle("SAVE");
                builder.setMessage("저장하시겠습니까?");
                builder.setIcon(android.R.drawable.ic_dialog_alert);
 
                builder.setPositiveButton("예"new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        SharedPreferences sharedPreferences = getSharedPreferences("first", MODE_PRIVATE);
                        SharedPreferences.Editor sharedPreferencesEditor = sharedPreferences.edit();
 
                        // 데이터를 기록한다.
                        sharedPreferencesEditor.putString("sampleString", editText.getText().toString());
                        sharedPreferencesEditor.apply();
                        Toast.makeText(MainActivity.this, editText.getText() + "이(가) 저장되었습니다.", Toast.LENGTH_LONG).show();
                    }
                });
                builder.setNegativeButton("아니오"null);
                builder.create().show();
                return true;
 
            case R.id.share:
                Intent sendIntent = new Intent();
                sendIntent.setAction(Intent.ACTION_SEND);
                sendIntent.putExtra(Intent.EXTRA_TEXT, editText.getText().toString());
                sendIntent.setType("text/plan");
                sendIntent.createChooser(sendIntent, "");
                startActivity(sendIntent);
                return true;
 
            case R.id.option:
                AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
                alertBuilder.setIcon(R.drawable.ic_settings_black_24dp);
                alertBuilder.setTitle("어느 색으로 하시겠습니까?");
 
                // List Adapter 생성
                final ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                        this,
                        android.R.layout.select_dialog_singlechoice);
                adapter.add("RED");
                adapter.add("GREEN");
                adapter.add("BLUE");
                adapter.add("기본값 설정");
 
                // 버튼 생성
                alertBuilder.setNegativeButton("취소",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                                int which) {
                                dialog.dismiss();
                            }
                        });
                alertBuilder.setAdapter(adapter,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                                int id) {
                                LinearLayout activity_main = (LinearLayout) findViewById(R.id.activity_main);
                                switch (id){
                                    case 0: editText.setTextColor(Color.rgb(255,0,0)); break;
                                    case 1: editText.setTextColor(Color.rgb(0,255,0)); break;
                                    case 2: editText.setTextColor(Color.rgb(0,0,255)); break;
                                    case 4: editText.setTextColor(Color.rgb(0,0,0)); break;
                                }
                                // AlertDialog 안에 있는 AlertDialog
                                String strName = adapter.getItem(id);
                            }
                        });
                alertBuilder.show();
                break;
        }
        return super.onOptionsItemSelected(item);
    }
 
}
cs


댓글

  1. 안녕하세요 왕초보입니다.
    메모장 소스검색하다가 들어왔는데.. DB나 SQL도 같이 병행해서 쓰셨나요..ㅠㅠ? 거기에 대한설명은 없어서 궁금해서요 ㅜㅜ

    답글삭제

댓글 쓰기

이 블로그의 인기 게시물

[C 언어] 하노이 탑 Tower of Hanoi

[안드로이드 스튜디오 APK] 계산기 Calculator 오픈소스