2

I am trying to create a borderless button, but I also have many other styles for my button and I want to design button borderless by embedding code into my style.xml file.

One way I found was: By using style="?android:attr/borderlessButtonStyle" in my layout file.

<Button
    android:id="@+id/button_send"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_send"
    android:onClick="sendMessage"
    style="?android:attr/borderlessButtonStyle" />

But I want to make this happen in style.xml and I don't know what values does ' _______ take?

Ashutosh Sharma
  • 118
  • 2
  • 18
  • Have you tried extending from [Widget.AppCompat.Button.Borderless](https://stackoverflow.com/a/36666660/1815052)? – SqueezyMo Sep 07 '17 at 15:06

3 Answers3

2

You can do this by making Custom Button class which extend default Button class, and use this class everywhere, and second possible solution is use

If it's selected or not selected you should use a toggle button https://developer.android.com/reference/android/widget/ToggleButton.html

Be aware that there are still 4 states for that

You define them in a selector like this

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:state_pressed="true" android:drawable="@drawable/likeactivepressed" />
    <item android:state_pressed="true" android:drawable="@drawable/likeinitialpressed"/>
    <item android:state_checked="true" android:drawable="@drawable/likeon"/>
    <item android:drawable="@drawable/likeinitial"/>
</selector>

Then define it in your button like this

android:background="@drawable/like_button"
Sandip Savaliya
  • 784
  • 6
  • 19
1

I think this is what you're looking for.

<style name="style_name" parent="@style/Widget.AppCompat.Button.Borderless">
    <!-- your style -->
</style>
  • Welcome to Stack Overflow. While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value.[How to Answer](https://stackoverflow.com/help/how-to-answer) – Elletlar Nov 23 '18 at 08:06
0

Try this here and another

android:background="?android:attr/selectableItemBackground"
Akhilesh V S
  • 71
  • 1
  • 5