Android how to make button text bold when pressed or focussed

后端 未结 3 1201
执念已碎
执念已碎 2020-12-08 21:28

I want to change the text inside a button to be bold when the button is highlighted or pressed. I currently use a xml file to define the button and use the XML to change how

3条回答
  •  温柔的废话
    2020-12-08 22:06

    You could try putting the bold code inside the click event for the button:

    final Button button = (Button) findViewById(R.id.button_id);
             button.setOnClickListener(new View.OnClickListener() {
                 public void onClick(View v) {
                     // Set bold on click
                     button.setTypeface(null, Typeface.BOLD);
                 }
             });
    

提交回复
热议问题