使用SeekBar更改TextView大小

时间:2015-11-27 11:25:30

标签: android seekbar text-size

当我尝试通过在代码<<<<<<<<<<<<

中添加一个常量值来改变(EditText)中的文本大小时效果很好
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    EditText Text = (EditText)findViewById(R.id.editText);
    SeekBar f = (SeekBar)findViewById(R.id.seekBar);

    Text.setTextSize(55);

    Text.setText("Hello");



}

但是我无法通过使用SeekBar来实现它:

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


    EditText Text = (EditText)findViewById(R.id.editText);
    SeekBar f = (SeekBar)findViewById(R.id.seekBar);

    Text.setTextSize((float)f.getProgress());

    Text.setText("Hello");



}

1 个答案:

答案 0 :(得分:1)

您可以使用此侦听器更改文本大小:

f.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {       

    @Override       
    public void onStopTrackingTouch(SeekBar seekBar) {      
        // TODO Auto-generated method stub      
    }       

    @Override       
    public void onStartTrackingTouch(SeekBar seekBar) {     
        // TODO Auto-generated method stub      
    }       

    @Override       
    public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {     
        // TODO Auto-generated method stub      

        Text.setTextSize(progress);

    }