0% found this document useful (0 votes)
58 views3 pages

PRG 7

The document describes a program that uses a linear layout to create an Android application. The application takes text from a predefined TextView and displays it in an EditText after converting it to uppercase, changing the color, font, and size when a button is clicked.

Uploaded by

Syed Salman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views3 pages

PRG 7

The document describes a program that uses a linear layout to create an Android application. The application takes text from a predefined TextView and displays it in an EditText after converting it to uppercase, changing the color, font, and size when a button is clicked.

Uploaded by

Syed Salman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Program 7: Use linear layout to create a simple application that will take the

contents of a predefined textview and use a button to cause the application to


take that text, convert it to uppercase, colour, font family and size and display it
in an edittext field.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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">

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

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/convert" />

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.prg7;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity


{

private TextView textView;


private EditText editText;

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

textView = findViewById(R.id.textView);
Button button = findViewById(R.id.button);
editText = findViewById(R.id.editText);

button.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
String text =
textView.getText().toString().toUpperCase();
editText.setText(text);
editText.setTextColor(Color.RED);
editText.setTypeface(Typeface.SANS_SERIF);
editText.setTextSize(20);
}
});
}
}

You might also like