Reputation: 70
i'm trying to customize my alert dialog. but i can not change the background color of buttons. i tried drawable button designing, style, setting direct color in xml and also setting color by java codes in the activity but i could not change it. the shape of the button changes but the color only can be either the default color or transparent color.
the xml coding of button itself:
<Button
android:id="@+id/btnDenied"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="35dp"
android:layout_marginBottom="15dp"
android:background="@drawable/button_selected" //// or @drawable/button_costume
android:text="@string/button_no" />
the selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed = "true">
<shape>
<solid android:color="#FFEB3B"/>
</shape>
</item>
<item android:state_pressed = "false">
<shape>
<solid android:color="#FFC107"/>
</shape>
</item>
</selector>
and another drawable file:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="50dp"/>
<solid
android:color="@color/colorHeader"/>
</shape>
and i also tried this style:
<style name="Button_Style"
parent="@android:style/Widget.Button">
<item name="android:textSize">14sp</item>
<item name="android:background">@color/colorHeader</item>
<item name="android:textColor">#1B1B22</item>
<item name="android:textStyle">bold</item>
<item name="android:layout_margin">2dp</item>
</style>
but non of them could change the color of the button.
Upvotes: 1
Views: 213
Reputation: 1091
The code that I have written is 100 percent correct, but sometimes Android Studio does some wrong tasks, so solve these issues either by running the program again, or doing the following steps:
Clean Project , From the build menu .
Rebuild Project .
And I got this problem with me not to show errors in xml file, I hope this thing helped you.
Upvotes: 1