import
android.graphics.Color;
import
android.os.Bundle;
import
android.view.Gravity;
import
android.widget.Button;
import
android.widget.TextSwitcher;
import
android.widget.TextView;
import
androidx.appcompat.app.AppCompatActivity;
public
class
MainActivity
extends
AppCompatActivity {
private
TextSwitcher textSwitcher;
private
Button nextButton;
private
int
stringIndex =
0
;
private
String[] row = {
"Hi!"
,
"Welcome"
,
"to"
,
"Geeks"
,
"for"
,
"Geeks"
};
private
TextView textView;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textSwitcher = findViewById(R.id.textSwitcher);
nextButton = findViewById(R.id.button);
nextButton.setOnClickListener(v -> {
if
(stringIndex == row.length -
1
) {
stringIndex =
0
;
textSwitcher.setText(row[stringIndex]);
}
else
{
textSwitcher.setText(row[++stringIndex]);
}
});
textSwitcher.setFactory(() -> {
textView =
new
TextView(MainActivity.
this
);
textView.setTextSize(
60
);
textView.setGravity(Gravity.CENTER_HORIZONTAL);
textView.setTextColor(Color.parseColor(
"#0F9D58"
));
return
textView;
});
textSwitcher.setText(row[stringIndex]);
}
}