0

How can I change color of rounded corners textView or button with transparent background like this image

I want when clicked again the button unselect , not only select

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
PinhaDooido
  • 63
  • 1
  • 9
  • 1
    Possible duplicate of [Android button with different background colors](https://stackoverflow.com/questions/3738886/android-button-with-different-background-colors) – Keivan Esbati Oct 14 '18 at 07:58
  • Possible duplicate of [How to make the corners of a button round?](https://stackoverflow.com/questions/6054562/how-to-make-the-corners-of-a-button-round) – Ali Khaki Oct 14 '18 at 14:00

3 Answers3

3

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..

Intsab Haider
  • 3,491
  • 3
  • 23
  • 32
1

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>
Farshid roohi
  • 722
  • 9
  • 23
No Body
  • 671
  • 5
  • 14
0

You have different options:

Something like:

    <com.google.android.material.button.MaterialButton
        style="@style/Widget.MaterialComponents.Button.OutlinedButton"
        android:text="BUTTON"
        app:strokeColor="@color/myColor"
        app:cornerRadius="16dp"
        ../>

enter image description here

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>

Something like:

    <com.google.android.material.chip.Chip
        style="@style/Widget.MaterialComponents.Chip.Entry"
        app:chipCornerRadius="16dp"
        android:text="Chip"
        .../>

enter image description here

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841