programdan
programdan

Reputation: 23

How do I change the size of the full text of the program?

I have a setting layout to change my appearance app. I want to put a SeekBar to change all of text size in my app. But I don't know what to do to get it done. I would appreciate if you guide me.

Upvotes: 0

Views: 43

Answers (1)

Muhammadjon
Muhammadjon

Reputation: 1506

Try this

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="14sp"
    android:text="Text" />

<SeekBar
    android:id="@+id/seekBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp" />

</LinearLayout>

onCreateMethod of MainActivity class:

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


    final TextView textView = findViewById(R.id.textView);
    SeekBar seekBar = findViewById(R.id.seekBar);


    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            textView.setTextSize(progress);

        }
    });
}

Try to modify this code as your preference.

Upvotes: 3

Related Questions