Android
Android
EditText inputText;
TextView resultText;
Button reverseButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
inputText = findViewById(R.id.inputText);
resultText = findViewById(R.id.resultText);
reverseButton = findViewById(R.id.reverseButton);
reverseButton.setOnClickListener(v -> {
String text = inputText.getText().toString();
String reversedText = new StringBuilder(text).reverse().toString();
resultText.setText("Reversed String: " + reversedText);
});
}
}
</LinearLayout>
-------------------------------------------------------------------------------
background
package com.example.backgroundcolorchange;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.constraintlayout.widget.ConstraintLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
<Button
android:id="@+id/changeColorButton" <!-- Button ID -->
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Background Color"
android:layout_marginTop="100dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:textSize="18sp" />
</androidx.constraintlayout.widget.ConstraintLayout>