I'm developing an android app using Java, using which one will be able to enter a text or group of texts using an EditText and once a button is clicked, the font-family of the text should be changed and be displayed in a TextView. The part I'm confused with is, how to change the font-family of a text on a button click. (Everytime I click the font family must change)
Here is the code of my MainActivity.java file
package com.example.fonter;
import androidx.appcompat.app.AppCompatActivity;
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 {
EditText mEditText;
Button changeFontBtn;
TextView resultTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mEditText = findViewById(R.id.editText);
changeFontBtn = findViewById(R.id.fontChangeBtn);
resultTextView = findViewById(R.id.resultView);
changeFontBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fontChangeFn();
}
});
}
public void fontChangeFn () {
if (mEditText.getText().toString().trim().length() > 0) {
// This is the part I'm confused with.
}
}
}
Any help or suggestion would be really appreciated.