Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change text size in <selector> when state_pressed = true

I would like to have this

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" style="@style/font_size_increase"/>
</selector>

and it seems that this one is not supported anymore.

I wonder if there is another way to increase the text size (in xml) when it is pressed?

Many thanks!

like image 654
Huy Than Avatar asked Nov 09 '22 17:11

Huy Than


1 Answers

UPDATED CODE-- Create your own dimens.xml file and then set it on selector like this

 <resources>
     <item name="text_size" type="integer">10dp</item>
  </resources>

Then use in java code-

 textView.setOnTouchListener( new OnTouchListener() {

    @Override
    public boolean onTouch( View v, MotionEvent event ) {

        switch(event) {
            case MotionEvent.ACTION_DOWN:
                textView.setTextSize(this.getResources().getDimension(R.id.text_size));
                break;
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:

        }
        return false;
    }
} );
like image 141
Gopal Singh Avatar answered Nov 15 '22 12:11

Gopal Singh