-1

I am not a native Android dev, but am learning by modifying react-native native packages.

I was trying to use the native Button component and progrmatically make changes to make it look like the Play store buttons of "uninstall" which is transparent background and a border. And also the solid "open" button. I am only able to get it to be "borderless" with:

super(context, null, android.R.attr.borderlessButtonStyle)

or regular raised:

super(context)

Here is screenshot of Play store buttons, does anyone know how to make these programmatically. Including toggling the android.R.attr.borderlessButtonStyle progrmatically.

Noitidart
  • 35,443
  • 37
  • 154
  • 323
  • 1
    you need to create an xml drawable for that, and set it as a background. https://stackoverflow.com/questions/7690416/android-border-for-button?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Gennadii Saprykin May 11 '18 at 15:58
  • You asked the same question twice 5 minutes apart... – HB. May 11 '18 at 16:21
  • @H.Brooks that was a react-native question on accesing configMap in constructor, i gave this situation as an example. – Noitidart May 11 '18 at 21:31

1 Answers1

1

You need to make your own drawable. Here is an example. Do not use this, just copy and modify as it is not your requested style, it is simply an example.

   <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape>
            <solid
                android:color="#000000" />
            <stroke
                android:width="1dp"
                android:color="#ffffff" />
            <corners
                android:radius="4dp" />
            <padding
                android:left="6dp"
                android:top="6dp"
                android:right="6dp"
                android:bottom="6dp" />
        </shape>
    </item>
    <item>
        <shape>
            <solid
                android:color="#90aabbcc" />
            <stroke
                android:width="1dp"
                android:color="#ffffff" />
            <corners
                android:radius="4dp" />
            <padding
                android:left="6dp"
                android:top="6dp"
                android:right="6dp"
                android:bottom="6dp" />
        </shape>
    </item>
</selector>

Of course, do you own colors, your own border or no border, and corner radius and you are done.

Sam
  • 5,342
  • 1
  • 23
  • 39
  • Thank you, +1, but this is not progrmattic though I was hoping to create a AppCompat Button and just change the tint to a color. I am especially interested in toggling `android.R.attr.borderlessButtonStyle` progrmatically. – Noitidart May 11 '18 at 21:32
  • well, to toggle the look of a button you can either use a selector like above so it changes on events of interactions, which was kind of what you were asking to do, or you can have two buttons overlaid on each other and toggle visibility between the two, sharing the same click, or you can adjust the properties of the button in code like the background drawable, or you can make a custom button that extends button and add a toggle property to it. There are many ways to skin that cat, but you can't "specifically" change the xml style attribute at run time. but you can do any of the other options – Sam May 11 '18 at 22:47
  • Thanks Sam, I'm struggling with it but I think this is the right direction. I'll keep trying and share with you on success. :) If you have any input it would be awesome if you can share, this module here is creating it without xml, in runtime - https://github.com/adbayb/react-native-android-kit/blob/master/android/src/main/java/fr/aybadb/rnak/components/button/ButtonView.java#L11 - i was trying to modify this module to support borderless and non-borderless. – Noitidart May 15 '18 at 21:58