Tuesday, November 1, 2022

PROGRAM 04:- AIM: - Create “Hello World” application. That will display “Hello World” in the middle of the screen in the red color with white background.

 

Code:-

 

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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"
   
tools:context=".MainActivity">

<
TextView
   
android:layout_width="wrap_content"
   
android:layout_height="wrap_content"
   
android:layout_gravity="center"
   
android:text="Hello World!"
   
android:textColor="#800000"
   
android:textSize="60sp"
   
android:textStyle="bold"
   
app:layout_constraintBottom_toBottomOf="parent"
   
app:layout_constraintLeft_toLeftOf="parent"
   
app:layout_constraintRight_toRightOf="parent"
   
app:layout_constraintTop_toTopOf="parent" />


</
androidx.coordinatorlayout.widget.CoordinatorLayout>

 

 

Java Code :

 

package com.example.helloworld;

import android.os.Bundle;

import com.google.android.material.snackbar.Snackbar;

import androidx.appcompat.app.AppCompatActivity;

import android.view.View;

import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import com.example.helloworld.databinding.ActivityMainBinding;

import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity {

   
private AppBarConfiguration appBarConfiguration;
   
private ActivityMainBinding binding;

   
@Override
   
protected void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);

       
binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(
binding.getRoot());



    }

   
@Override
   
public boolean onCreateOptionsMenu(Menu menu) {
       
// Inflate the menu; this adds items to the action bar if it is present.
       
getMenuInflater().inflate(R.menu.menu_main,menu);
       
return true;
    }

   
@Override
   
public boolean onOptionsItemSelected(MenuItem item) {
       
// Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
       
int id = item.getItemId();

       
//noinspection SimplifiableIfStatement
       
if (id == R.id.action_settings) {
           
return true;
        }

       
return super.onOptionsItemSelected(item);
    }

   
@Override
   
public boolean onSupportNavigateUp() {
       
NavController navController = Navigation.findNavController(this,R.id.nav_host_fragment_content_main);
       
return NavigationUI.navigateUp(navController,appBarConfiguration)
                ||
super.onSupportNavigateUp();
    }
}

 

Output:-





No comments:

Post a Comment

PROGRAM 05 : AIM: - To understand Activity , Intent

  Code:- XML Code:   Activity_main.xml <? xml version ="1.0" encoding ="utf-8" ?> < androidx.constrain...