Я хочу изменить текст внутри кнопки, чтобы быть полужирным, когда кнопка подсвечивается или нажимается. В настоящее время я использую xml файл для определения кнопки и использования XML для изменения способа отображения при нажатии, но я хотел бы сделать это без использования изображения.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/reset_hover" />
<item android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/reset_hover" />
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/reset_hover" />
<item android:drawable="@drawable/reset" />
</selector>
Я попытался использовать что-то вроде следующего, но он, кажется, никогда не вызван.
final Button btn_reset = (Button) findViewById(R.id.btn_reset);
btn_reset.setOnClickListener(this);
btn_reset.setOn(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus){btn_reset.setTypeface(null, Typeface.BOLD);}
else{btn_reset.setTypeface(null, Typeface.NORMAL);}
}
});