Android how to make button text bold when pressed or focussed
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); } });
Attention! See update below
You could create your own style.xml in which you define the text style. In your selector you can reference to the style.style.xml
<style name="myStyle"> <item name="android:textSize">9px</item> <item name="android:gravity">center_horizontal</item> <item name="android:textColor">#fff</item> <item name="android:textStyle">bold</item></style>
And in your selector
<selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:state_focused="true" android:state_pressed="false" style="@style/myStyle" /> </selector>
Update 2020: My answer is more than 10 years old. It doesn´t work anymore!
Styles are not allowed in selectors. Reference
And to make the text bold, use this code:
btn_reset.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { // When the user clicks the Button case MotionEvent.ACTION_DOWN: btn_reset.setTypeface(Typeface.DEFAULT_BOLD); break; // When the user releases the Button case MotionEvent.ACTION_UP: btn_reset.setTypeface(Typeface.DEFAULT); break; } return false; }});