How can I change color of rounded corners textView or button with transparent background like this
I want when clicked again the button unselect , not only select
How can I change color of rounded corners textView or button with transparent background like this
I want when clicked again the button unselect , not only select
Add xml file in drawable folder bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<!-- you can use any color you want I used here gray color-->
<stroke
android:height="1.0dip"
android:width="1.0dip"
android:color="#ffee82ee" />
<solid android:color="@android:color/transparent"/>
<corners android:radius="7dp"/>
</shape>
and in layout
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg"
android:textColor="#ffee82ee"/>
It will work..
You can use a selector with multiple state as drawable for background and text color.
<Button
android:id="@+id/button1"
android:background="@drawable/selector_xml_name"
android:layout_width="200dp"
android:layout_height="126dp"
android:text="Hello" />
drawable xml file :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/numpad_button_bg_selected" android:state_selected="true"></item>
<item android:drawable="@drawable/numpad_button_bg_pressed" android:state_pressed="true"></item>
<item android:drawable="@drawable/numpad_button_bg_normal"></item>
</selector>
You have different options:
MaterialButton
in the Material Components library with the Widget.MaterialComponents.Button.OutlinedButton
style and the app:cornerRadius
, app:strokeColor
attributes.Something like:
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:text="BUTTON"
app:strokeColor="@color/myColor"
app:cornerRadius="16dp"
../>
To achieve the selection of the buttons you can use a MaterialButtonToggleGroup
.
Something like:
<com.google.android.material.button.MaterialButtonToggleGroup
app:singleSelection="true"
...>
<com.google.android.material.button.MaterialButton
.../>
</com.google.android.material.button.MaterialButtonToggleGroup>
Chip
Something like:
<com.google.android.material.chip.Chip
style="@style/Widget.MaterialComponents.Chip.Entry"
app:chipCornerRadius="16dp"
android:text="Chip"
.../>