简体   繁体   中英

how to save seekbar thumb position in shared prefrence

I'm Change TextView size on seekbar and save value in Shared Preference. i wanna to set text size minimum 12sp and maximum 60sp. when i set text size (anything) then i wanna to set seekbar thumb also set on same position as text size. In my coding i saved text size in shared preference successfully but i do not know that how i set seekbar thumb position as same as text size.

Seekbar sb;
TextView textView;

sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_PX,seekBar.getProgress());
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });




SharedPref.setValue(EditTextView.this,"TextSize",textView.getTextSize());

I'm Create a seprate Shared Prefrence class which i using for all values. Can You Help Me that how i save seekbar thump position and textsize both same when i reopen app.

.......Sorry For My Bad English......

You can try this:

textView.setTextSize(TypedValue.COMPLEX_UNIT_SP,SharedPref.getValue(EditTextView.this,"TextSize"));
sb.setProgress(SharedPref.getValue(EditTextView.this,"TextSize"));
sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, progress);
        SharedPref.setValue(EditTextView.this,"TextSize", progress);
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
    }
});

Set default value is 12 in SharedPref like this:

int textSize = sharedPref.getInt("TextView", 12);

And set max and min value

<SeekBar
   android:id="@+id/seekBar"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:max="60"
   android:min="12"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM