Ad Code

How to make a simple text editor app for Android in Android Studio | Text editor free project source for java

Hello User, In this Article I will share with you how to make a simple text editor app in Android studio java. If you want to get more free source codes for Android then please subscribe our YouTube channel and bookmark our site.




This project is workable and tested in all Android versions including Android 12 and 13. This project is just for a bigginer who have joined coding community recently. You can design this project yourself. You can also convert this project into a Html Editor, Java code Editor .. etc according to your interest.

Maake a project in Android studio. Make files by the given filename. after maked copy all codes into that spesific file. Now go to AndroidManifest.xml file and declare these activity. Make sure you have created FileUtil.java file. If you did not added then You can add from here.

Here is the project source code

Add codes into your project carefully for avoiding errors

MainActivity.java
package com.queen.girlchat;

import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
import static android.os.Build.VERSION.SDK_INT;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.PopupMenu;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import android.app.AlertDialog;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.applovin.mediation.MaxAd;
import com.applovin.mediation.MaxAdListener;
import com.applovin.mediation.MaxAdViewAdListener;
import com.applovin.mediation.MaxError;
import com.applovin.mediation.ads.MaxAdView;
import com.applovin.mediation.ads.MaxInterstitialAd;
import com.applovin.sdk.AppLovinSdk;
import com.applovin.sdk.AppLovinSdkConfiguration;

import java.util.Locale;

public class MainActivity extends AppCompatActivity {

    EditText edittext1;
    ImageView saveButton, menuButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        edittext1 = findViewById(R.id.edittext1);
        saveButton = findViewById(R.id.saveButton);
        menuButton  = findViewById(R.id.menuButton);

        if(!checkPermission()) {
            requestPermission();
        }
        

        menuButton.setOnClickListener(new View.OnClickListener() {

            @Override public void onClick(View _view) {


                PopupMenu popup = new PopupMenu(MainActivity.this,  menuButton);

                Menu menu = popup.getMenu();
                menu.add("Share");
                menu.add("Terms & Condition");
                menu.add("Privacy Policy");

                popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                    public boolean onMenuItemClick(MenuItem item) {
                        switch (item.getTitle().toString()) {

                            case "Share":

                                Intent shareIntent = new Intent(Intent.ACTION_SEND);
                                shareIntent.setType("text/*");
                                shareIntent.putExtra(Intent.EXTRA_TEXT, "https://play.google.com/store/apps/details?id=com.queen.girlchat");
                                startActivity(Intent.createChooser(shareIntent, "Share File"));

                                return true;

                            case "Terms & Condition":


                                Intent i = new Intent(Intent.ACTION_VIEW);
                                i.setData(Uri.parse("https://queengirlchatprivacypolicy.blogspot.com/2022/07/terms-conditions-by-downloading-or.html"));
                                startActivity(i);

                                return true;

                            case "Privacy Policy":


                                Intent i2 = new Intent(Intent.ACTION_VIEW);
                                i2.setData(Uri.parse("https://queengirlchatprivacypolicy.blogspot.com/2022/07/privacy-policy-rahul-kumar-meena-built.html"));
                                startActivity(i2);

                                return true;


                            default: return false;
                        }
                    }

                });


                popup.show();

            }
        });


        saveButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if(!edittext1.getText().toString().equals("")) {

                    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MainActivity.this);

                    LayoutInflater inflater = MainActivity.this.getLayoutInflater();
                    View dialogView = inflater.inflate(R.layout.layout1, null);
                    dialogBuilder.setView(dialogView);

                    AlertDialog alertDialog = dialogBuilder.create();

                    EditText fileName = dialogView.findViewById(R.id.fileName);
                    Button saveButton = dialogView.findViewById(R.id.saveButton);


                    saveButton.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {

                            if(!fileName.getText().toString().equals("")) {


                                FileUtil.writeFile(FileUtil.getExternalStorageDir().concat("/Download/").concat(fileName.getText().toString()), edittext1.getText().toString());
                                alertDialog.cancel();

                                Toast.makeText(getApplicationContext(), "File Saved Successfully \n\nPath : /External Storage/Download/", Toast.LENGTH_SHORT).show();
                                

                            } else {
                                Toast.makeText(getApplicationContext(), "Please Enter Filename", Toast.LENGTH_SHORT).show();
                            }
                        }
                    });


                    alertDialog.show();






                } else {
                    Toast.makeText(getApplicationContext(), "Please enter code first", Toast.LENGTH_SHORT).show();
                }

            }
        });

    }

    private void requestPermission() {
        if (SDK_INT >= Build.VERSION_CODES.R) {

            if (ContextCompat.checkSelfPermission(this, READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
                ActivityCompat.requestPermissions(this, new String[] {READ_EXTERNAL_STORAGE}, 1000);

            }

        } else {
            if (ContextCompat.checkSelfPermission(this, READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED
                    || ContextCompat.checkSelfPermission(this, WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
                ActivityCompat.requestPermissions(this, new String[] {READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE}, 1000);

            }
        }
    }

    private boolean checkPermission() {
        if (SDK_INT >= Build.VERSION_CODES.R) {

            int result = ContextCompat.checkSelfPermission(MainActivity.this, READ_EXTERNAL_STORAGE);
            return result == PackageManager.PERMISSION_GRANTED;

        } else {
            int result = ContextCompat.checkSelfPermission(MainActivity.this, READ_EXTERNAL_STORAGE);
            int result1 = ContextCompat.checkSelfPermission(MainActivity.this, WRITE_EXTERNAL_STORAGE);
            return result == PackageManager.PERMISSION_GRANTED && result1 == PackageManager.PERMISSION_GRANTED;
        }
    }

    
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
    tools:context=".MainActivity">


    <LinearLayout
        android:layout_width="match_parent"
        android:background="@color/purple_500"
        android:gravity="center_vertical"
        android:layout_height="50dp">


        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center_vertical"
            android:text="@string/app_name"
            android:textColor="@color/white"
            android:textStyle="bold"
            android:layout_marginLeft="10dp"
            android:layout_weight="1"
            android:textSize="20sp"/>


        <ImageView
            android:id="@+id/saveButton"
            android:layout_width="25dp"
            android:layout_marginRight="15dp"
            android:src="@drawable/ic_baseline_save_as_24"
            android:layout_height="25dp"/>

        <ImageView
            android:id="@+id/menuButton"
            android:layout_width="25dp"
            android:layout_marginRight="10dp"
            android:src="@drawable/ic_baseline_more_vert_24"
            android:layout_height="25dp"/>

    </LinearLayout>


    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="8dp"
        android:layout_weight="1"
        app:cardCornerRadius="10dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:layout_height="match_parent">

            <EditText
                android:id="@+id/edittext1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:inputType="textMultiLine"
                android:gravity="top"
                android:padding="8dp"
                android:textSize="12sp"
                android:background="@color/black"
                android:textColor="#BCB8B8"
                android:layout_weight="1"
                android:textColorHint="#686666"
                android:hint="Enter your code  here"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:gravity="center"
                android:layout_height="wrap_content">

                <LinearLayout
                    android:id="@+id/adLayout"
                    android:gravity="center"
                    android:layout_width="match_parent"
                    android:orientation="vertical"
                    android:visibility="gone"
                    android:layout_height="50dp"/>


            </LinearLayout>



        </LinearLayout>


    </androidx.cardview.widget.CardView>






</LinearLayout>
Add these Permissions
<uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Add this in application tag in Manifest
android:requestLegacyExternalStorage="true"
Declare Activity in Manifest
<activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

Now add vector drawable in the drawable file from android studio.

Thank you for visiting our site. If you want to more free source code then please be with us. We will upload thease type of projects as soon as possible.

Post a Comment

0 Comments

Ad Code