896+ Capstone Project is Available: Whatsapp: +91-7011258995, Email: sharecodepoint@gmail.com

How to create simple notepad android app using android studio

This tutorial in on how to create a simple (notepoint) notepad android  app using android studio. A simple notepad that support Select All/ Copy/ Font size/  Font style and New document. Missing functions & features coming next version.

Notepoint project is a android app is implemented in android studio. You can download notepoint android app with source code.

How to import the project : 
Create new project . You just need to copy the code then paste that code into your project.
Notepoint android app features :
  • Menu bar for style, edit, format and view
  • Edit text with copy function with toast.
  • Format texts with changing the font size.
  • To create a new document.txt file.

Step 1: 
Firstly import the package of android files.
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
import android.graphics.Typeface;
 
Step 2:
First we want to create a notepoint layout. Add 6 buttons for operations (like : bold, italic, normal, copy and more). Add 1 MultiAutoCompleteTextView Or EditText.

activity_main.xml
<Button
    android:layout_width="40dp"
    android:layout_height="wrap_content"
    android:text="B"
    android:textStyle="bold"
    android:id="@+id/boldtext"
    android:onClick="onClick()"
    />
    <Button
        android:layout_width="40dp"
        android:layout_height="wrap_content"
        android:textStyle="italic"
        android:layout_toRightOf="@+id/boldtext"
        android:text="I"
        android:id="@+id/italictext"
        android:onClick="onClick"
        />
    <Button
        android:layout_width="40dp"
        android:layout_height="wrap_content"
        android:textStyle="normal"
        android:text="N"
        android:layout_toRightOf="@+id/italictext"
        android:id="@+id/normaltext"
        android:onClick="onClick"
        />
    <Button
        android:layout_height="wrap_content"
        android:text="Size"
        android:layout_width="wrap_content"
        android:id="@+id/fontsize"
        android:layout_toRightOf="@+id/normaltext"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Copy"
        android:id="@+id/copytext"
        android:layout_toRightOf="@+id/fontsize"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="new"
        android:layout_toRightOf="@+id/copytext"
        android:id="@+id/newdoc"
        />
 
      <MultiAutoCompleteTextView
        android:id="@+id/mainpart"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:ems="100"
        android:gravity="top|left"
          android:padding="10dp"
        android:inputType="textMultiLine"
        android:hint="Welcome to Notepoint"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
          android:layout_below="@+id/boldtext"
          android:background="@color/editbordercolor"/>
 
 
For each operation, we created a ActionListner and give the appropriate for each.

Step 3: 
In this code you get following :
1. How to change the text color in android studio.
2. How to change the text font size in android studio.
3. How to show the message in Toast.
4. How to create contextmenu in android studio and more.

MainActivity.java
import android.content.res.TypedArray;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.*;
import android.util.TypedValue;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
import android.graphics.Typeface;
import  android.widget.PopupMenu;
 
public class MainActivity extends AppCompatActivity implements OnClickListener {
 
    MultiAutoCompleteTextView mainview;
    String copydata;
    Button btn_bold,btn_italic,btn_normal,btn_size,btn_copydata,btn_new,btn_save;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        btn_bold = (Button) findViewById(R.id.boldtext);
        btn_italic =(Button) findViewById(R.id.italictext);
        btn_normal =(Button) findViewById(R.id.normaltext);
        btn_size =(Button) findViewById(R.id.fontsize);
        btn_copydata =(Button) findViewById(R.id.copytext);
        btn_new =(Button) findViewById(R.id.newdoc);
 
 
        mainview = (MultiAutoCompleteTextView) findViewById(R.id.mainpart);
 
        btn_bold.setOnClickListener(this);
        btn_italic.setOnClickListener(this);
        btn_normal.setOnClickListener(this);
        btn_size.setOnClickListener(this);
        btn_new.setOnClickListener(this);
        btn_copydata.setOnClickListener(this);
 
        registerForContextMenu(btn_size);
    }
    public  void onClick(View view) {
        if (view == btn_bold) {
            Typeface setfontstyle = Typeface.defaultFromStyle(Typeface.BOLD);
            mainview.setTypeface(setfontstyle);
            Toast.makeText(getApplicationContext(), "Bold", Toast.LENGTH_LONG).show();
        } else if (view == btn_italic) {
                Typeface setfontstyle = Typeface.defaultFromStyle(Typeface.ITALIC);
                mainview.setTypeface(setfontstyle);
            Toast.makeText(getApplicationContext(), "Italic", Toast.LENGTH_LONG).show();
        } else if (view == btn_normal) {
            Typeface setfontstyle = Typeface.defaultFromStyle(Typeface.NORMAL);
            mainview.setTypeface(setfontstyle);
            Toast.makeText(getApplicationContext(), "Normal", Toast.LENGTH_LONG).show();
        }
        else if (view == btn_size) {
            view.showContextMenu();
            Toast.makeText(getApplicationContext(), "Font Size", Toast.LENGTH_LONG).show();
        }
        else if(view == btn_new)
        {
            String appnametitle ="Notepoint";
            setTitle(appnametitle+" - New Document.txt");
            mainview.setText("");
            mainview.setHint("New Document");
            mainview.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
            Toast.makeText(getApplicationContext(), "New Document", Toast.LENGTH_LONG).show();
        }
        else if(view == btn_copydata)
        {
 
 
            copydata = mainview.getText().toString();
                copydata = mainview.getText().toString();
                Toast.makeText(getApplicationContext(), "Copied Successfully !!", Toast.LENGTH_LONG).show();
 
        }
    }
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo)
    {
        super.onCreateContextMenu(menu, v, menuInfo);
 
        menu.setHeaderTitle("Select Font Size");
        menu.add(0, v.getId(), 0, "5+");
        menu.add(0, v.getId(), 0, "10+");
        menu.add(0, v.getId(), 0, "20+");
        menu.add(0, v.getId(), 0, "25+");
        menu.add(0, v.getId(), 0, "30+");
        menu.add(0, v.getId(), 0, "35+");
        menu.add(0, v.getId(), 0, "40+");
        menu.add(0, v.getId(), 0, "45+");
        menu.add(0, v.getId(), 0, "50");
    }
    @Override
    public boolean onContextItemSelected(MenuItem item){
 
            if (item.getTitle() == "5+") {
                mainview.setTextSize(TypedValue.COMPLEX_UNIT_SP, 8);
            } else if (item.getTitle() == "10+") {
                mainview.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
            } else if (item.getTitle() == "20+") {
                mainview.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
            } else if (item.getTitle() == "25+") {
                mainview.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24);
            } else if (item.getTitle() == "30+") {
                mainview.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
            } else if (item.getTitle() == "35+") {
                mainview.setTextSize(TypedValue.COMPLEX_UNIT_SP, 33);
            } else if (item.getTitle() == "40+") {
                mainview.setTextSize(TypedValue.COMPLEX_UNIT_SP, 43);
            } else if (item.getTitle() == "45+") {
                mainview.setTextSize(TypedValue.COMPLEX_UNIT_SP, 48);
            } else if (item.getTitle() == "50") {
                mainview.setTextSize(TypedValue.COMPLEX_UNIT_SP, 50);
            } else {
                Toast.makeText(getApplicationContext(), "Something is Worng", Toast.LENGTH_LONG).show();
            }
        return true;
    }
} 
 
Step 4:
How to change line color in ( EditText and MultiAutoCompleteTextView ).
Add one xml file in you project. Give any name what you want.

bordercolor.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <solid android:color="#ffffff" />
    <stroke android:width="1dip" android:color="#ffffff" />
</selector>
That's it! Download the files. Thanks for reading!

Video : create simple notepad android app

If you have any doubt regarding the creation of android app then leave your doubts in the comment box.

How to create notepad in java : check out

Sharecodepoint

Sharecodepoint is the junction where every essential thing is shared for college students in the well-defined packets of codes. We are focused on providing you the best material package like Question papers, MCQ'S, and one NIGHT STUDY MATERIAL. facebook twitter youtube instagram

1 Comments

Previous Post Next Post

Contact Form