ivan ivan - 1 month ago 12
Android Question

How to use volume's button to zoom in/out text in textview

How to override and use volume buttons to zoom IN/OUT text inside in layout, similar as when you are writing/reading SMS ?

Answer

Please check this solution

public class MainActivity extends AppCompatActivity {

TextView txt;

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

    txt = (TextView) findViewById(R.id.OpenClose);
}

public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        float x = txt.getScaleX();
        float y = txt.getScaleY();

        txt.setScaleX(x-1);
        txt.setScaleY(y-1);
        return true;
    } 
    else if(keyCode == KeyEvent.KEYCODE_VOLUME_UP)
    {
        float x = txt.getScaleX();
        float y = txt.getScaleY();

        txt.setScaleX(x+1);
        txt.setScaleY(y+1);
        return true;
    }
    else
    {
        return super.onKeyDown(keyCode, event);
    }
}
}