で定義されたカスタム ボタン スタイルがありますstyles.xml
。
<style name="buttonBlack">
<item name="android:background">@drawable/selector_button_black_bg</item>
<item name="android:textColor">@android:color/white</item>
</style>
レイアウト xml で設定すると、正常に動作します。
<Button style="@style/buttonBlack" ... />
コードで設定すると機能しません (空のボタンが表示され、背景が表示されません):
Button button = new Button(this, null, R.style.buttonBlack);
ここで何が間違っていますか?
セレクターは次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/button_black_pressed" />
<item android:state_focused="true" android:drawable="@drawable/button_black_focused" />
<item android:drawable="@drawable/button_black_normal" />
</selector>