Professional Documents
Culture Documents
Design an app in which you have to display your name in the middle
of the screen with red color and each time when you click on a button,
name will increase with font size and after increasing 5 times, means at
sixth time, it will not increase and display a message “you can’t perform
this operation”;
XML Code::
<TextView
android:id="@+id/textView"
android:layout_width="337dp"
android:layout_height="195dp"
android:layout_marginTop="218dp"
android:layout_marginBottom="84dp"
android:background="@android:color/holo_red_dark"
android:gravity="center"
android:text="Harsh Rajput"
android:textSize="16dp"
android:textStyle="bold"
app:autoSizeTextType="none"
app:layout_constraintBottom_toTopOf="@+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="147dp"
android:layout_height="59dp"
android:layout_marginStart="104dp"
android:layout_marginBottom="329dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</androidx.constraintlayout.widget.ConstraintLayout>
Java code::
package com.example.androidpractical;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button=findViewById(R.id.button);
textView=findViewById(R.id.textView);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(flag<=4){
i+=4;
flag++;
textView.setTextSize(i);
}
else{
Toast.makeText(getApplicationContext(), "you can’t perform
this operation", Toast.LENGTH_SHORT).show();
}
}
});
}
}