I am trying to change style of the button after clicking on it.
My plan: when user clicks on the button it change background color (orange -> white), border (none->orange border), text color (white->green).
But when I did it with drawable shape (for border as it says here), it changed background colour to orange (stroke color) and not to white (as I write for solid in shape and for buttonPressed.setBackgroundColor
method in function pressSemButton
just in case).
If I don't use drawable shape with border it works and background color changes to white.
My function for changing button's style:
public void pressSemButton(Button buttonPressed, Button button) {
buttonPressed.setBackground(getResources().getDrawable(R.drawable.orange_white_border));
buttonPressed.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.white));
buttonPressed.setTextColor(getResources().getColor(R.color.green_dark));
}
XML for orange_white_border:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="@color/white" />
<corners android:radius="30dp"/>
<stroke android:width="2dp" android:color="@color/orange_light"/>
</shape>
XML code for button in fragment's XML:
<Button
android:id="@+id/firstSemesterButton"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text= "@string/buttonFirstSem"
app:layout_constraintStart_toStartOf="parent"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
/>
What can I do to change background color of button to white with implementing orange_white_border for border on it?