Showing posts with label #Android-codes. Show all posts
Showing posts with label #Android-codes. Show all posts

Friday, June 24, 2022

How we add copy Text button in android studio

 Toast.makeText(conditional_statement_activity.this, "Text Copied", Toast.LENGTH_SHORT).show();

ClipboardManager clipboardManager=(ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip=ClipData.newPlainText("TextView",tc11.getText().toString());
clipboardManager.setPrimaryClip(clip);
clip.getDescription();

How we add share Text Button in android studio

 Toast.makeText(conditional_statement_activity.this, "Share Text", Toast.LENGTH_SHORT).show();

String sharetext=tc11.getText().toString();
Intent sendIntent=new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT , sharetext);
startActivity(sendIntent);

Wednesday, June 22, 2022

What are Layouts in Android Studio

 Android Layout is used to define the user interface that holds the UI controls or widgets that will appear on the screen of an android application or activity screen.

Types of Layouts:

1. Linear Layout horizontal

We use this layout to place the elements in a linear manner. A Linear manner means one element per line. This layout creates various kinds of forms on Android.It is shown above where the widgets such as TextViews, and all in a vertical manner.

2. Linear Layout vertical

We use this layout to place the elements in a linear manner. A Linear manner means one element per line. This layout creates various kinds of forms on Android.It is shown above where the widgets such as TextViews, and all in a horizontal manner.

3. Constraint Layout

A ConstraintLayout is a ViewGroup which allows you to position and size widgets in a flexible way. 

4. Table Layout

TableLayout is a ViewGroup that displays child View elements in rows and columns.

5. Relative Layout

This layout is for specifying the position of the elements in relation to the other elements that are present there.

In the relative layout, alignment of the position of the elements to the parent container is possible.

6. Frame Layout

Frame Layout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view.


How we create new project in Android Studio.

     1. First we open our Android Studio.

     2. Then Click on new project.

     3. Then Select Activity from this

     4. Then give name to your project and select the language for your project.

Thursday, January 27, 2022

How we use simple Alert Dialog Box in android studio

Add above the OnCreate method:

private ProgressDialog progressDialog;

Add in the OnCreate method:

ProgressDialog progressDialog = new ProgressDialog(this);

than add this code after this method:
new AlertDialog.Builder(MainActivity.this)
.setIcon(R.drawable.ic_baseline_warning_24)
.setTitle("Exit")
.setMessage("Are you want to exit from this app!")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
finish();
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
}).show();




Monday, January 17, 2022

How we use OnClickListener and simple Toast in android Studio

 package com.example.practice_section;


import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Button button2,button3; // here we define the id
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().hide();
button2=findViewById(R.id.button2); //here we find the button by id
button3=findViewById(R.id.button3);
button2.setOnClickListener(new View.OnClickListener() { //this is the method of writing oncclicklistener
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "You have been Sign Up", Toast.LENGTH_SHORT).show(); //this is the method of writing toast
}
});
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "You have been sign In", Toast.LENGTH_SHORT).show();
}
});

}
}

Friday, September 17, 2021

How we use Splash Screen in Android Studio.

                          Java code for simple splash screen Activity

Add this in Java class of Splash screen

getSupportActionBar().hide();
Thread thread=new Thread(new Runnable() {
@Override
public void run() {
try {
sleep(5000);
Intent i=new Intent(splash_screen.this,MainActivity.class);
startActivity(i);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
});
thread.start();


Change the names of Main_activity and splash_activity in manifest file with one another.


Add this in manifest file in splash activity

android:noHistory="true"